home of the madduck/ blog/
Django: a beautiful and truly thin web development framework

Take the following URL:


and imagine the following Python function:

def summary(request, year, month, day):
    response = HttpResponse()
    // do something
    return response

If you see a relation between the two, then Django is for you. The missing part is a URL mapping, a list of regular expressions, which transforms a URL into a keyword list, and maps it to a function (a HTTP view, as it's called):

    mysite.wow.summary, {'additional':'information'})

You do not have to use keyword arguments, positional parameters will work as well, and you can do anything you like within the powers of regular expressions, but the result is always along the same lines:

When someone visits the above URL, Django calls the above summary(…) function (defined in the modules mysite/wow.py) and passes an object encapsulating the request, along with the components from the URL as parameters:

summary(request, 2009, 05, 21, {'additional':'information'})

It then renders the return value. The function can also throw an exception if it need to communicate e.g. a 404 error. Very clean, and there are even generic views if your data doesn't need any massaging, of if you just want to do standard things like generate PDFs.

This is the core idea of Django, which I've gathered from one talk and four hours of invested time. It's a truly thin layer, and its elegance made me bouncey.

The QUERY STRING of the request will be passed in the request object, along with all the other CGI variables you're familiar with. Django provides a large number of helpers and shortcuts to save you from having to do the ugly work, including topics such as internationalisation, syndication, authentication, file uploads, and caching.

In addition, Django gives you an object-relational_mapper to map the data into, and manage the data definition within your favourite RDBMS, a templating language designed to fit in with the whole philosophy, and widgets to work with forms.

You do not have to use any of those. You are free to use any other Python module for the task, just as you can use all of the other features of and modules written for Python. This is particularly powerful in the context of the middleware layer.

There's also a large number of pluggable applications and snippets for re-use.

The only concern I have at this point is whether features like tagging are going to find their way into the framework, because tracking numerous external plugins for a site and keeping them working across versions reminds me of the nightmares I had with Zope and Plone (I stopped working with (and on) those before I had a chance to dive into version 3 of each).

The fact that Django leaves data storage to other tools (in fact, it's entirely up to you) makes those nightmares seem further distant.

All in all, I am excited to have had a chance to take a brief glance at the software, and I am looking forward to doing more with it. Unfortunately, it looks like it will take quite some time to wade through existing plugins and design the rest of an application that can finally replace the horrific dung-pile that is my homepage.