Django First Impressions

Posted 16 May 2007 under , ,

I’ve spent a fair bit of time playing with the Django web framework over the last few weeks. It’s been interesting to compare and contrast it with my current favorite, Ruby on Rails. Both use the MVC design pattern (or in Django’s case, MVT — more on that later), both are written in high-level scripting languages, and both have passionate communities surrounding them. Here are some of my initial impressions.

Admin Interface

This is TOO SWEET. Django will automatically build an administrative interface for your web application using the model definitions you create. At first, I dismissed this as similar to RoR’s scaffolding feature: great for marketing purposes (see the famous 15 Minute Blog video), but functionally useless for anything but the most basic application. But no! This is the real deal — beautiful, tweakable, production-ready administrative interfaces that free up developer time for more creative enterprises. I’m in love. I wonder if I can find something similar as a Rails plugin?

Relationship Modeling for Dummies

Defining the relationships between your Django models is a very simple and elegant affair. In my Post class, I have the following:

class Post(models.Model):
  author = models.ForeignKey(User)
  tags = models.ManyToManyField(Tag)

These two lines tell Django that each post has one author and many tags, each of which might be associated with many posts. From there, Django will automatically add an “author_id” field to the Post model and create a “post_tag” table to tie posts and tags together. I haven’t yet tried to model more complex relationships, such as a three-way join or a join containing additional information describing the relationship. Although intended to save time and simplify object modeling, I could see this feature costing more time and effort than it saves in some complex cases.

Database Management

Django lacks anything as sophisticated as RoR’s migration system for modifying databases. You can easily create a database from your model definitions, but you’re on your own if you want to create new models or update existing ones without upsetting the data already in place. A database management system would go a long, long way toward bringing Django up to speed with Rails; it looks like there are some efforts underway to make this happen.

Conventions

It seems like Django places an emphasis on decoupling the different parts of an application, to the detriment of those wanting to build something small and self-contained. For example, in Django …

  1. You create a “project”, and then within that project, you can create multiple “apps”. I’m just trying to make a blog, not Microsoft Office.
  2. Rather than storing your templates with the other files of an application, Django has you store them in a completely separate location, and then point to that location in your settings file.
  3. Serving non-Python files, like images and stylesheets, is more complex than it should be. I really like the way Rails handles these resources, with a “public” directory.
  4. Finally, the “view” receives user input, interacts with the models, and then calls a “template” to display the results. I thought the model-view-controller paradigm was fine the way it was — why mess with it?

Finally

Overall, I’m impressed. The Django framework has a lot going for it. If I were going to rebuild this website today, the administrative interface generation and efficient modeling techniques would make choosing it extremely tempting. Additionally, I think Django would be ideal for a beginning web programmer — I can’t imagine you’d need much technical experience to create a full-featured site, at least until it comes time to get the thing hosted :)

I’ll be very curious to see how Django develops as it approaches version 1.0 and beyond. Will it move toward simple and streamlined, powerful and complex, or some incredible combination of the two?

Further reading on the Django framework:


About Me

I’m the Development Director at Viget in Durham, North Carolina. I’m also an avid reader, traveler, cyclist, musician, coffee fiend, and friend of birds.