500 Error With WSGI in Django

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:

My httpd.conf changes look like this:

WSGIScriptAlias / /home/miketnc/frontend/tncsite/wsgi.py
WSGIPythonPath /home/miketnc/frontend/tncsite

<Directory /home/miketnc/frontend/tncsite>
<Files wsgi.py>
Order deny,allow
Allow from all

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:

import os, sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tncsite.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

This causes a 500 error:

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.

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.

Any ideas?


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.

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'."

The Hello World script still runs fine, the trigger for the error is the final line:

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

I've set all directories containing the project from frontend/ down to 777 and I've added a daemon process as myself:

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

<Directory /home/miketnc/frontend/tncsite>
<Files wsgi.py>
Order deny,allow
Allow from all

Anyone please able to advise further on how to get this working?


In your case:

WSGIPythonPath /home/miketnc/frontend/tncsite

is redundant, as your are setting sys.path in the WSGI script file.

What you are missing though is adding the parent directory of the site:


This is in addition to the existing line adding '/home/miketnc/frontend/tncsite'.



and watch:


which talk about paths and permissions.

Need Your Help

rails 3.1 database query

ruby-on-rails database

I have a rails 3.1 app with the following Models:

flashsocket on socketio and nodejs not working

flash node.js socket.io

I'm trying to get flashsocket working with socket.io but it does not, always going in xhr-polling fallback.