开发者

Automatically import models on Django shell launch

开发者 https://www.devze.com 2023-02-07 17:46 出处:网络
I\'m tired of typing from account_import.models import ImportFile every time I open my Django shell. Is there a way to automatically run th开发者_高级运维is command whenever I fire up my shell?install

I'm tired of typing from account_import.models import ImportFile every time I open my Django shell. Is there a way to automatically run th开发者_高级运维is command whenever I fire up my shell?


install django-extensions, one of the commands it features (shell_plus) is providing the context for your models. https://github.com/django-extensions/django-extensions

So, instead of ./manage.py shell you can use ./manage.py shell_plus so that everything is imported.


http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP

If you set the environment variable PYTHONSTARTUP to a file, this will be run first whenever you start a python shell.

0

精彩评论

暂无评论...
验证码 换一张
取 消