Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Rails and Django Head to Head

Rails and Django Head to Head

Thanks to a couple of web developers, we now have a fairly objective comparison of Ruby on Rails and Python's Django framework. Ben Askins and Alan Green jointly specified and then developed parallel implementations of a simple web app for sharing book reviews. Their report and source code are available online. They conclude that neither framework is clearly superior to the other, so it's probably best to stick with the one written in the language of your choice. There are, however some important caveats which make the decision a bit more complicated.

No need to introduce Ruby on Rails here, but it's worth noting that Django stands out in the Python world for two reasons: Google has clearly put its weight behind it, and Guido van Rossum, Python's benevolent dictator, has taken the very unusual step of blessing it instead of other equally well regarded choices. Also, Alan and Ben point out that "Django [...] does not ape Ruby on Rails".

When comparing line counts between the web apps implemented by the authors, Rails beats Django with 4% less lines overall. Although the templates in Django are much more verbose, that framework provides an admin interface almost for free so they actually wrote less Python than Ruby code. For development time they clocked 25:45 hours for the Rails implementation, compared to 16:36 in Django. Of course we can't tell whether Ben or Alan code faster, but again they attribute the difference to the need to code admin forms in Rails, while Django generated them from just a few hints in the model. The authors recommend investigating Rails plug-ins such as AutoAdmin and Streamlined to compensate for that.

The paper points out that Rails makes using AJAX easier with RJS and the integrated JavaScript libraries, while Django includes JSON functions, but leaves all JavaScript coding and even the choice of client-side libraries to the developer. JavaScript wizards may prefer Django's hands-off approach, but everybody else benefits from the built-in AJAX support in Rails.

On the other hand, they note the Python framework offers better infrastructure for internationalization thanks to native unicode support and gettext message substitution, allowing for multi-lingual sites with localised responses to individual HTTP requests.

A major advantage for Rails is the migrations mechanism which facilitates experimentation and evolution of the data model, even for apps already in production. Django has nothing of the sort. If Alan and Ben had omitted the migrations from the line count, their own numbers show that the Ruby and Python code would be about the same size and, after adding the templates, the Rails solution would have 15% less lines of code than the Django one, even while providing custom admin pages. So here the authors compared apples to (non-existent) oranges, with a bias which favored Django.

Mr. Green and Mr. Askins wrap it up diplomatically: "While choosing between these two frameworks may be difficult, the good news is that either framework is a good choice a team wishing to develop a web application." If advanced internationalization is a requirement for you, their analysis suggests Django is the best choice. Those who don't need that but want ready-to-use AJAX functionality, anticipate lots of different templates and crave the comfort of database migrations will benefit most from Ruby on Rails.

Rate this Article