I have recently set up a web server, which currently hosts a couple of static page websites, and two django projects.
the two django projects are ‘abc’ and ‘xyz’ and are in separate directories respectively, in the home folder. Each have their own wsgi script which points to their respective settings.py file.
Recently though, I have been noticing a few 500 errors on ‘xyz’. Usually a refresh will correct the problem, but this isn’t acceptable, so I checked the apache error.log, and noticed that sometimes when I hit ‘xyz’ there is an exception raised about cannot find abc.settings in the xyz project. Somehow these two projects are crossing over and interfering with each other. I have not worked on abc enough yet to know if the problem is the same the other way around. Below is my exception.
[Sun Jul 08 13:30:34 2012] [error] Traceback (most recent call last):
[Sun Jul 08 13:30:34 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 219, in __call__
[Sun Jul 08 13:30:34 2012] [error] self.load_middleware()
[Sun Jul 08 13:30:34 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 39, in load_middleware
[Sun Jul 08 13:30:34 2012] [error] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Sun Jul 08 13:30:34 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner
[Sun Jul 08 13:30:34 2012] [error] self._setup()
[Sun Jul 08 13:30:34 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
[Sun Jul 08 13:30:34 2012] [error] self._wrapped = Settings(settings_module)
[Sun Jul 08 13:30:34 2012] [error] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 95, in __init__
[Sun Jul 08 13:30:34 2012] [error] raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Sun Jul 08 13:30:34 2012] [error] ImportError: Could not import settings 'abc.settings' (Is it on sys.path?): No module named scalamoosh.settings
Any help/advice would be greatly appreciated. Cheers
The issue you’re running in to is that while mod_wsgi gives each Django app its own python interpreter, they still share the same OS environment which is where Django stores the name of the setting module. The work-around I found was to change the name of the enviroment variable that Django looks for the settings module in before creating the WSGI application object.
My slightly modified wsgi.py looks something like this: