Why do I need the DJANGO_SETTINGS_MODULE set?

前端 未结 3 661
挽巷
挽巷 2021-02-02 00:42

Every time I log on to my server through SSH I need to type the following:

export DJANGO_SETTINGS_MODULE=settings

if I do not any usage of the

3条回答
  •  终归单人心
    2021-02-02 01:16

    Yourmanage.py is referencing an application (notifications). This forces Django to complain about DJANGO_SETTINGS_MODULE being set because the Django environment hasn't been set up yet.

    Incidentally, you can force the enviroment setup manually, but honestly I wouldn't do this in manage.py. That's not really a good practice in my opinion.

    Here is how you can manually setup the Django environment from within any app (or program for that matter):

    # set up the environment using the settings module
    from django.core.management import setup_environ
    from myapp import settings
    setup_environ(settings)
    

提交回复
热议问题