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.