Q:

Django on a Mac: Apache with mod_wsgi configuration problems

I'm trying to run a local Django server on Apache with mod_wsgi. I am running the out-of-the-box Apache on Mac.
hobbes3@hobbes3:~/Sites/mysite$ apachectl -v
Server version: Apache/2.2.21 (Unix)
Server built:   Nov 15 2011 15:12:57

Apache properly loads mod_wsgi.
hobbes3@hobbes3:~/Sites/mysite$ apachectl -t -D DUMP_MODULES | grep wsgi
Syntax OK
wsgi_module (shared)

In my httpd.conf file I load apache_django_wsgi.conf which is
WSGIDaemonProcess django
WSGIProcessGroup django

Alias /mysite/ "/Users/hobbes3/Sites/mysite/"
<Directory "/Users/hobbes3/Sites/mysite">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>

WSGIScriptAlias /mysite "/Users/hobbes3/Sites/mysite/apache/django.wsgi"

<Directory "/Users/hobbes3/Sites/mysite/apache">
Allow from all
</Directory>

My django.wsgi file is
import os
import sys

paths = [ '/Users/hobbes3/Sites/mysite',
          '/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages',
]

for path in paths:
    if path not in sys.path:
        sys.path.append(path)

sys.executable = '/usr/local/bin/python'
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I can also restart Apache without any error. But when I try to visit http://localhost/mysite, my browser says I have a 500 Internal Server Error.
My Apache error log says (I truncated the dates and times):
mod_wsgi (pid=73970): Exception occurred processing WSGI script '/Users/hobbes3/Sites/mysite/apache/django.wsgi'.
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
    self.load_middleware()
  File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/core/handlers/base.py", line 39, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:
  File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/django/conf/__init__.py", line 89, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'mysite.settings' (Is it on sys.path?): No module named mysite.settings

I don't know why it can't import mysite.settings, didn't I include that in the sys.path?
The full path to settings.py is /Users/hobbes3/Sites/mysite/.

A:

You've included mysite in the path, but you've referenced mysite.settings. So Python is looking for a mysite module within the directories it finds on the path. Use just settings instead.

