1

I am serving a Django site on Apache2 server with mod_wsgi. Here is what my mysite/mysite directory looks like:

(mysite_venv)➜  mysite  tree mysite -I "*.pyc"
    mysite
    ├── __init__.py
    ├── db.sqlite3
    ├── settings
    │   ├── __init__.py
    │   ├── base.py
    │   └── local.py
    ├── urls.py
    └── wsgi.py

When I run this project using python manage.py runmodwsgi I get an Internal Server Error with this message in the logs:

[wsgi:error] [pid 8900] ImportError:         No module named mysite.settings.local
[mpm_prefork:notice] [pid 8898] AH00170: caught SIGWINCH, shutting down gracefully

Here is what my manage.py looks like:

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings.local")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

But when I change the directory mysite/mysite like this:

(mysite_venv)➜  mysite  tree mysite -I "*.pyc"
mysite
├── __init__.py
├── base.py
├── db.sqlite3
├── local.py
├── urls.py
└── wsgi.py

And change the code os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings.local") to os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.local") the server runs OK! How can I fix this issue?

PS: When I use python manage.py runserver to run this project, everthing is OK too.

Here is what my sys.path looks like:

/Users/gagaxiaolong/PycharmProjects/mysite
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python27.zip
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7/plat-darwin
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7/plat-mac
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7/plat-mac/lib-scriptpackages
/Users/gagaxiaolong/.virtualenvs/mysite_venv/Extras/lib/python
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7/lib-tk
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7/lib-old
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7/site-packages
/Users/gagaxiaolong/.virtualenvs/mysite_venv/lib/python2.7/site-packages/IPython/extensions

There is a similar question asked 9 months ago :How to debug basic issues configuring django to be served with apache and mod-wsgi?, I tried the ways mentioned in the answer but does not work.

Community
  • 1
  • 1
  • If you are running multiple Django sites, make sure you read http://blog.dscpl.com.au/2012/10/requests-running-in-wrong-django.html and take head of warnings about use of ``os.environ.setdefault()`` in the ``wsgi.py`` file. – Graham Dumpleton Aug 14 '15 at 06:30

1 Answers1

0

You need to check sys.path in your manage.py file (use pdb for this). I think it is because you have a directory structure like this 'parent_dir/mysite/mysite/settings/' and your sys.path has an entry 'parent_dir'. So system is trying to find settings module in parent_dir/mysite. Change your manage.py to debug

import os
import sys

if __name__ == "__main__":
    import ipdb; ipdb.set_trace()
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings.local")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)
Rajesh Kaushik
  • 1,471
  • 1
  • 11
  • 16
  • Suggesting ``pdb`` or similar when using Apache/mod_wsgi is not necessarily a good idea as it isn't that simple to set up. This is because the process is demonised and there is no attached terminal, so you cannot interact with it via the terminal easily. – Graham Dumpleton Aug 14 '15 at 06:28
  • Debug using runserver not on apache (at remote server). Add logs if you are interested in path while running on apache. – Rajesh Kaushik Aug 14 '15 at 06:38