Django = Awesome
May 16, 2008 – 12:03 pm Tags: Django, Python, Zend FrameworkSo in the lack of anything “useful” to post, and in the attemps to at least post something interesting, I shall dedicate this post to talking about what makes Django such an awesome framework!
I’m going to compare it to Zend Framework, as it’s the framework I’m most familiar with.
Reduce redundancy
Django has many features to reduce the amount of redundant code you need to write.
- Generic Views
- Forms
- Modelforms
- Automatic admin panel
Generic views
This was initially slightly confusing to me, but then I figured it out. Django’s “generic views” are basically kind of like functions - they perform some task based on the parameters you pass to them.
Instead of always writing an action in a controller for all your requests, you can create a generic view for common tasks, which could for example be a list of something in your database.
Combined with Django’s way of defining URLs separately for all actions, you can do some things in your app even without writing anything else than a url pattern.
Forms
Django’s newforms library makes it really easy to do forms. Just define a form class using the simple methods provided and you can have a nice form with validation ready in no time.
Comparing this to ZF, it’s really a lot less of typing. In ZF, the syntax for defining the form is longer, but not by much, but the main factor is that in it you’ll need to define the validation by hand. Of course, if you don’t like Django’s validation, it’s easy to define custom validation for it as well… it just has sensible defaults, which in my opinion is a Good Thing ™
Modelforms
Django’s modelforms basically let you create forms based on your models by just defining a form class and adding a Meta class parameter that tells which model class the form is for. You won’t need to define any fields or anything, and you’ll get a ready-to-use form for creating and editing model data! Simply add a view that will display the form and call form.save() when done.
Often you will need to spend time to make forms to edit your DB stuff and with modelforms it’s almost no lines of code. Even relationships between objects work - you get a select box for one-to-many relations etc.
Of course, if needed, modelforms can be extended to perform their job a bit differently too. It will require a bit of going through Django’s code, though, as at least I wasn’t able to find any examples. Definitely doable and not too difficult if you know what you’re doing.
Automatic admin panel
This is one very very useful feature. Many many times I’ve written similar admin panel code for different projects - that stuff isn’t usually very reusable. Django all that away and gives you a great automagically generated admin panel which you can even customize to a good degree to make it even better. Need to create a database driven website? Just this should be a reason good enough you should definitely at least give Django a try - not to mention all the other things it has.
Unicode support
Python, unlike PHP, has good unicode support out of the box. No weird mbstring stuff or such, and Django’s svn release is fully unicode aware. Will make your life a whole lot easier if you need to work with multiple languages.
PS: Regarding Zend Framework
While Zend Framework has a different approach to things - it is meant to be loosely coupled etc. with most components being usable without needing the others, and Django has parts that are much more tightly coupled (like modelforms with the ORM) - it could still learn a thing or two from Django.












10 Responses to “Django = Awesome”
Luckily PHP 6 is going to have much improved unicode support, but the argument definitely stands for PHP 5 and earlier.
By Neil Garb on May 16, 2008
You forgot the capital letters in Good Thing™
Those do look like some nifty features though, and I can’t wait for PHP’s Unicode support.
By Vincent on May 16, 2008
I can tell you for a fact that the Zend Framework team is paying attention to- and learning from- Django. It definitely has some compelling features- no doubt- some of which Django itself has introduced to the web framework universe.
ZF is very different from Django in both design and MO. We are building it in a loosely coupled fashion with lots of extension points that, in my experience, simply takes more time. All of the features you mention are in our product backlog- well, except for the language-level unicode support :)- so I hope that you’ll find some of the features that you appreciate in Django available in ZF soon. Hopefully we’ll also catch your eye with some of the features that we hope to introduce to the web framework universe ourselves soon.
In any case, best of luck with whatever framework you’re using!
,Wil
By Wil Sinclair on May 16, 2008
PHP6? Well, I’m holding no hopes for its quick arrival+adoption - but who knows.
Fixed
Wil,
Yeah, in fact I did think some features of ZF are similar to Django’s

No worries, you are still my favorite in PHP-land
By Jani Hartikainen on May 16, 2008
Another feature of django’s that I really like is the arbitrary many-to-many relationships that you can set up. So Tag, for instance, can apply to many different models without you having to create, for example, TagVideo, TagBlog, TagArticle, etc.
I think this is only really practical in system which generate SQL from code, instead of the code describing the SQL structure (like ZF).
By Neil Garb on May 16, 2008
I think it’s pretty standard stuff in ORM libraries, (like Doctrine, Hibernate or wannabe-ORM like Propel), which is why I didn’t give it a special mention
By Jani Hartikainen on May 16, 2008
I’m totally naive when it comes to web programming - but would this sort of thing also be useful for retrieving information from a server via a desktop application.
Is it in a similar vein as Ruby on rails.
Web-programming and Erlang are two the things I want to spend some time getting up to speed with.
By Dan on May 25, 2008
Yeah, I think you could use Django to, for example, develop a JSON or XML based “interface” to some data residing on your server that you could then use in a desktop application.
I haven’t used Ruby on Rails (yet), but from what I’ve read and heard, Django is similar to it.
By Jani Hartikainen on May 25, 2008