Joe Yates' Blog

Programming and DevOps

A Rails Programmer's First Django Application

I’ve seen many comparisons of Rails with Django, its Python counterpart.

The Application

I decided to use Django to write a small local history application: the story of Snape in East Sussex.

The front and of the application uses a SIMILE timeline to display dates.

Personal Impressions about Django


The main thing I was looking forward to while writing the app was modularity. In fact, in the and I made two apps: the specific Snape application and a generic timeline app.

Creating the Database

In Rails, you launch script/generate Model and you obtain a database and a series of migrations, which form a chronology of development of the database.

In Django, you describe the database fields in your file and the run ‘ syncdb’.

The advantage of the Django system is that the model holds authoritative information about the fields in the database.

The great disadvantage is that there are no TABLE ALTERing migrations - you have to dump the table creation SQL and manually construct and run TABLE ALTER commands.


Django’s settings file ( more or less has to be site specific. So that means you have to decide what to check in to your version control system. Some people seem to use a ‘’ which they then copy to and alter tho the needs of a specific machine.

I chose to keep site specific stuff in a set of JSON files, named after the local machine (see It woks quite well, but in Rails as I commonly have a single development machine and a single production one, I am able to avoid the whole problem thanks to config/environments/[development|production].rb

Static Content

There is a difference between how one handles static files in development and production. Most people seem to use a hack in the file, indicating where to get static content if in DEBUG mode, whereas in production mode you are supposed to set up Apache aliases for the various directories.

The logic here is that Django should not get involved in serving static content (quite rightly), but it certainly makes setup more laborious. One can achieve a happy medium in Rails using X-SendFile - Rails gets the request and then punts serving to Apache.

Generating URLs

There is an equivalent to Rails' url_for which is available inside Django templates, it’s the filter { % url %}. Unfortunately, the first time I wanted to create a URL was actually in Python code - I wanted to redirect. I was unable to find a way to use url from Python code. There is get_absolute_url, which can be implemented inside the model, but it’s only for instances.


I think Django is fairly straightforward for the Rails programmer. The fact that you get a ‘free’ admin backend (similar to ActiveScaffold), is certainly handy. There are a lot of sources of online information and tutorials, so it’s quite easy to get up and running. The main impression I got was of a small framework - while Rails covers a great range of functionality, I felt I came up against Django limitations rather quickly. That may be due to not looking in the right places, but my Google searches showed that a lot of other people were asking the same questions.