Automatically import models on Django shell launch

后端 未结 2 767
庸人自扰
庸人自扰 2021-01-30 17:00

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 this command whenever I fir

相关标签:
2条回答
  • 2021-01-30 17:43

    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 讨论(0)
  • 2021-01-30 17:55

    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.

    0 讨论(0)
提交回复
热议问题