Jul 29, 2008

Deploying Django Project on Ubuntu Server

I've recently had to deploy a pretty simple Django application on Ubuntu server, and here're a few tips for myself in the future doing this once again.

For starters, there's a Jeff Baier's tutorial which covers most steps. There're, however, a couple of things I had to learn the hard way.

First, if you wish to use a stable version of Django, instead of dealing with subversion and compilation, just install it from repositories:

$ sudo apt-get install python-django

If you do so, your admin media will be in the following directory:


Second, in your .py files don't use relative imports. If you have a project named “project_one” and two applications, “app_one” and “app_two” applications, this will work on local django server, but won't work in production:

import app_one.Something

Instead, you must always do

import project_one.app_one.Something

Third, mind the paths to your media files. It's better to adjust them before deployment so they look the same on your development localhost and production server, otherwise you might have problems during deployment.

I'm mentioning this here because django's default recommended media/admin-media url configuration is somewhat doesn't makes this easier.

Finally, keep in mind that out-of-the-box MySQL databases are not UTF-8 which is not very good if you have any language in db besides English. Unless you won't unicode-enable your MySQL server before you create your tables structure, you will have to change encoding of all the tables after.

Pretty much that is it, which actually seems really smooth deployment process to me, so another score for Django.