Apache with Django and mod_wsgi
It's been a busy August for us, working on a number of new and existing projects, and a series of investor code reviews. We plan to start publicising one project in particular soon, helping people with their day-to-day management of IT. We put together a short survey which readers may be interested to complete if they have five minutes.
As usual, most of the development work we're doing at the moment is in Django, and we've recently switched to using mod_wsgi. In putting together our Apache and wsgi configuration, we found that neither mod_wsgi's nor Django's wsgi installation instructions contained a truly portable configuration include. We came up with the script below. It's far from perfect but it does the job for now:
# Assumes this is in the project root, parallel to settings.py, etc. # We'd typically have our 'docroot' folder one level down for security reasons. import os, sys, django.core.handlers.wsgi project = os.path.dirname(__file__) workspace = os.path.dirname( project ) sys.path.append( project ) sys.path.append( workspace ) os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % project.rpartition( '/' )[2] application = django.core.handlers.wsgi.WSGIHandler()
Happy hacking!