Yes. Django is just a regular Python module living in your site-packages. So when you import django.something
, the way Python decides which version to load is by walking down the Python path (import sys; print sys.path
) in order and looking for a directory called django (with something.py or something/_init_.py inside). It loads the first one it finds. So the quickest method is to modify this Python path before starting your project, which can be conveniently done with an environment variable named PYTHONPATH.
So for your Django 1.2 project, install Django 1.2 in site-packages/django-1.2 and then:
# run Django 1.2 for old app that I don't have time to update
cd ~gaearon/src/old-django-project
env PYTHONPATH=/Library/Python/2.6/site-packages/django-1.2 ./manage.py runserver
For all other (Django 1.3) projects, simply install Django as normal, which makes it the default:
# all other projects use the system default Django 1.3
cd ~gaearon/src/current-django-project
./manage.py runserver
For production servers you won't use runserver, but the PYTHONPATH will work wherever you invoke Python (i.e. flup, or manage.py runfcgi). If invoked from mod_python there is an Apache configuration directive to modify the Python path (see mod_python documentation).
Or you could use virtualenv.