Home > programming > Use multiple Django versions for development

Use multiple Django versions for development

September 23rd, 2009

To use multiple Django versions for development, you will need virtualenv. Virtualenv is a sandbox that allows you to use different versions of Python in your development machine.  It is a tool to create isolated Python environments.

I have been using Django 1.1 beta on my projects.  Just recently, I needed to use Django 1.0 for a new project.  Of course there were major differences from Django 1.0 versus Django 1.1 which could cause headaches.

An example is that Django 1.0 uses this on its urls.py:

(r'^admin/(.*)', admin.site.root)

while Django 1.1 uses this on its urls.py:

(r'^admin/', include(admin.site.urls))

So, inorder to use multiple Django versions for development on your machine, you will need:

Create a virtualenv directory.  This is your working directory for the particular Django version:

$ virtualenv --no-site-packages project-env

Create a requirements.txt to list your required Python applications:

Yolk

psycopg2

Django==1.0.3

Remember to change the 1.0.3 with any Django release version that you want for the virtual environment.

Install your project’s required python applications:

$ pip install -E project-env -r requirements.txt

Activate your virtual environment:

$ source project-env/bin/activate

This will change your shell path to show you are inside a virtual environment.

To de-activate your virtual environment:

(project-env) $ deactivate

Create a django project:

(project-env) $ cd project-env
(project-env) $ django-admin.py startproject <project name>

And you are done!

Bonus:

To verify which Python version you are using (your global Python packages directory or your virtual Python’s packages directory):

(project-env) $ which python

To verify which django-admin.py you are using:

(project-env) $ which django-admin.py

Happy Coding!

List of related articles on myListBoard.com:

Author: Cyril Pauya Categories: programming Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.