Posts tagged with “apache”…

Apache with Django and mod_wsgi

by Aidan Fitzpatrick

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!

This post has 0 comments »

Subscribe

rss Subscribe to our blog feed

Archive

January 2012
July 2011
April 2011
February 2011
June 2010
January 2010
October 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008

We write about…