Django Shell No module named settings

后端 未结 12 1364
温柔的废话
温柔的废话 2020-12-02 20:26

I\'ve deployed Django to Apache via mod_wsgi. Django is running fine when hosted from Apache. However, I\'m trying to do some maintenance via manage.py

相关标签:
12条回答
  • 2020-12-02 21:19

    Since your web app is working, check that you're running manage.py with the same python interpreter that's defined in your .wsgi file (and if you append other directories to sys.path in your .wsgi file, make sure they're in the pythonpath here too).

    If you try to import something in your settings file that throws an ImportError, Django tells you settings cannot be imported. Newer versions of django will mention (If the file settings.py does indeed exist, it's causing an ImportError somehow.) and I've run into this a few times.

    If it's not that, maybe try using django-admin.py instead, just in case something has gone wrong in your manage.py file. AFAIK there is no good reason to modify manage.py directly.

    0 讨论(0)
  • 2020-12-02 21:21

    Though Simon Whitaker's answer (that a same-name dir is confusing things) is certainly on point, rather than suggesting you change your entire extant dir structure, might I suggest:

    Instead of using the "malfunctioning" / ambiguous...

    import settings
    

    ...use the more specific...

    from django.conf import settings
    
    0 讨论(0)
  • 2020-12-02 21:22

    I had accidentally changed my DJANGO_SETTINGS_MODULE variable using the echo command: echo DJANGO_SETTINGS_MODULE=mysite.settings

    I simply quit virtualenv and activated it again, which restored my settings.

    0 讨论(0)
  • 2020-12-02 21:28

    Please check for compatibility between the virtualenv version and the django version. when it matches, it works like a gem.

    0 讨论(0)
  • 2020-12-02 21:29

    For me it was actually the PATH, so the project wasn't inside the path, I did this:

    export PYTHONPATH=/var/www/project:$PYTHONPATH

    If it's a local project it might be something like this:

    export PYTHONPATH=~/my-project:$PYTHONPATH

    Questions? comment and I'll answer.

    0 讨论(0)
  • 2020-12-02 21:32

    I had DJANGO_SETTINGS_MODULE set to "mealer.settings"

    (django-env)ali@a-N750JV:~/snap/projects-on-django/Rester$ export -p | grep DJANGO
    
    declare -x DJANGO_SETTINGS_MODULE="mealer.settings"
    

    which I removed by

    ali@ali-N750JV:~/snap/projects-on-django/Rester$ export -n  DJANGO_SETTINGS_MODULE
    
    (django-env)ali@ali-N750JV:~/snap/projects-on-django/Rester$ export -p | grep DJAN
    
    (django-env)ali@ali-N750JV:
    

    export -p | grep DJAN found nothing as you see

    this answer is based on answer by Paul Meinshausen

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