This Blog continues on

Wednesday, February 07, 2007

Thoughts on Django

What follows are some thoughts on django written by Isaac Alston, a friend of mine from university. He originally wrote it as a facebook note, but after reading it I asked if I could re-post it here. I think he gives an enlightening point of view on the experience of a python newcomer beginning to use django.

Here it is:

This is a short review of my experience with Django ( Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

In November, I was informed that the company I am working for would be leaving PHP behind. We had been looking for a faster, and cleaner development tool for a while and were deciding between Ruby on Rails ( and Django. I had a preference for Django immediately, since I could already program in Python, whereas Rails required Ruby skills.

After much debate and discussion, my company eventually chose to use Rails. My co-worker, flatmate and (dare I say it) friend, Maciej, is currently working on our latest project for a fish company with Rails, and has produced some spectacular results. I was determined that I could do the same with Python, and so (instead of learning Ruby) launched into the docs for Django. At about the same time, I was approached by my church and asked if I would be willing to develop a new website for them. I agreed to the suggestion, because I knew that the opportunity would allow me to learn Django at a slower pace, and in a low-pressure environment.

I was initially very impressed by Django. I have been coding with PHP for about three years now, and it's been slow, messy and difficult to work with at times. I was amazed at such 'auto-generation' features including the database API, and the Admin centre.

Three weeks into development however, Django's niggles and problems can be seen in full view. The main problem with Django is that its Admin centre is not flexible enough.

Django is in a constant state of flux because the developers are rewriting the forms model (the way in which forms on a website interact with the database). 'Newforms' as they are called, are going to replace 'old-forms'.

At present, the Admin panel still makes use of the old-forms model, and will not be rewritten with newforms for a while. This is the primary cause of it's inflexibility. For example, I wanted to perform some custom validation of uploads with the default Admin. All I wanted to do was check whether the file was of a 'music type' ie, mp3 or ogg or some such format. Yet it appears that this is either very difficult or impossible. I say this because I have received no replies from the Django mailing list.

It's very nice having the 'free' Admin there, but in the end, if one wants to build something really complex, one must develop a custom admin panel from scratch. This I suppose, isn't so terrible because that is what I was doing with PHP anyway; however, it is infuriating that I am forced to write additional code, when the current Admin is so close to being able to do it.

The current documentation recommends to build any new websites with the newforms model, and so I downloaded the development version and set to work. This was all well and good until I discovered that there is nearly no documentation for the newforms library. Indeed, as a result, when I set about adding a simple contact form to my site, it took three hours, THREE HOURS! This was because I was literally forced to browse the source code for Django, to try and figure out what was going on.

The third problem with Django, is that doing AJAX requires a little work (and of course, programmers are lazy). Rails has nice 'helper functions' which generate JavaScript for you, which Django lacks. This was the result of another huge debate that went on within the Django community, who didn't want to be seen as 'Rails copycats'. Anyway, the maintainers eventually decided that web developers should (and I paraphrase from a rant): "grow up and learn to use JavaScript properly", so for people like me who have managed to get by copy-pasting JavaScript all these years, it means we'll have to sit down and learn it. Why should we though? Rails developers aren't... ;-).

I think that Django will be great when it gets the newforms library fully implemented (in the Admin as well) and in the current release (rather than the development version which constantly changes). I think it'll be great when there's some more documentation for newforms. Until then, I'm probably going to move to Pylons (, which a friend has recommended and which seems to be more Rails-like, offering a lot more flexibility. It also offers the nice 'AJAX helper functions' which I so desire, and also seems to have a more powerful ORM (Object Relational Mapping) implementation than Django's. I could of course learn Ruby, but, well... yeah.