Article / 8th Aug 2008

Dual Django Version Fun

With the recent massive changes to Django trunk - newforms-admin being the biggest - I've found a need to run both oldforms-admin and newforms-admin versions in both development and production; here's a quick HOWTO on both.

Development is arguably easier, although at times more annoying. The easy way, and the one I used, is the one blogged about by Patrick Altman, where you have a small script to change what your Python sees as the django module, which you can run each time you change project to a different version. His uses subversion checkouts every time; I prefer the one below, which chooses one of a set of already-checked-out Djangos, allowing quicker (and offline) changing:

#!/bin/sh
sudo rm /usr/lib/python2.5/site-packages/django
sudo ln -s /home/andrew/Programs/django-$1/django /usr/lib/python2.5/site-packages/django

Obviously this needs changing for wherever you keep your code; however, I have two folders in ~/Programs, django-trunk and django-0.97, so I just run something like "djangoswitch 0.97".

Production is a little trickier, but cleaner. Since you need to run more than one site at once, you can't go around relinking the django directory. However, all you have to do instead is tell mod_python (if you're using that method of deployment) you want a different Django version with a line like this:

PythonPath "['/usr/local/django/django_1.0'] + sys.path"

where all your other PythonBlah lines are in your Apache config. (Note, on my server the global version is 0.97-pre-svn, so I have a special override to 1.0 for my one app that uses it currently - this blog).

FastCGI is somewhat harder, but LastGraph doesn't need upgrading yet. I imagine it might take something like virtualenv to do it (or edit the manage.py script to twiddle with sys.path at the start).