title: 500 Error With WSGI in Django
body: <p>I'm deploying my first ever Django project and I get the feeling I'm very close, but just need some help getting over the line. Here's the problem:</p>
  
  <p>My httpd.conf changes look like this:</p>
  
  <pre><code>WSGIScriptAlias / /home/miketnc/frontend/tncsite/wsgi.py
  WSGIPythonPath /home/miketnc/frontend/tncsite
  
  &lt;Directory /home/miketnc/frontend/tncsite&gt;
  &lt;Files wsgi.py&gt;
  Order deny,allow
  Allow from all
  &lt;/Files&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p>So far so good, the "hello world" script in wsgi.py runs just fine. The problem comes when I use the Django doc-recommended wsgi script:</p>
  
  <pre><code>import os, sys
  
  sys.path.append('/home/miketnc/frontend/tncsite')
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tncsite.settings")
  
  from django.core.wsgi import get_wsgi_application
  application = get_wsgi_application()
  </code></pre>
  
  <p>This causes a 500 error:</p>
  
  <pre><code>File "/home/miketnc/frontend/tncsite/wsgi.py", line 10, in ?
  mod_wsgi (pid=15494): Exception occurred processing WSGI script '/home/miketnc/frontend/tncsite/wsgi.py'.
  mod_wsgi (pid=15494): Target WSGI script '/home/miketnc/frontend/tncsite/wsgi.py' cannot be loaded as Python module.
  </code></pre>
  
  <p>All of the support I've seen on the error relates back to bad installations in apache, not finding modules etc, which can't be the case if "hello world" is running.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After restarting on a fresh server, I've managed to move things forward slightly. The good news is that python and WSGI seem to be playing nice, the bad is that I'm now getting a different kind of 500 error. </p>
  
  <p>The only error I'm getting back in the log is:
      "[Mon Dec 05 18:22:45 2011] [error] [client ip] mod_wsgi (pid=19804): Exception occurred processing WSGI script '/home/miketnc/frontend/tncsite/apache/wsgi.py'."</p>
  
  <p>The Hello World script still runs fine, the trigger for the error is the final line:</p>
  
  <pre><code>application = django.core.handlers.wsgi.WSGIHandler()
  </code></pre>
  
  <p>I've set all directories containing the project from frontend/ down to 777 and I've added a daemon process as myself:</p>
  
  <pre><code>LoadModule wsgi_module /usr/local/apache/extramodules/mod_wsgi.so
  AddHandler wsgi-script .wsgi
  
  WSGIDaemonProcess miketnc processes=2 maximum-requests=500 threads=1
  WSGIProcessGroup miketnc
  
  WSGIScriptAlias / /home/miketnc/frontend/tncsite/apache/wsgi.py
  
  &lt;Directory /home/miketnc/frontend/tncsite&gt;
  &lt;Files wsgi.py&gt;
  Order deny,allow
  Allow from all
  &lt;/Files&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p>Anyone please able to advise further on how to get this working?</p>