Impressions on Django (II): Development environment
On my previous post, I explained some basic ideas on how Django works. The post explained, mostly the programming model which is a clever implementation of the classical Model-View-Controller pattern . Not that new. But compared to other web development environments I worked with (PHP , Zope /Plone or plain mod_python ), Django is a clear improvement because is both simple and pragmatical.
The programming model is something that has a direct impact on how you design the product, but there are other factors that determine how easy a developer can develop within a platform. In this post I arge about such factors, how Django afects the development workflow.
Editing and controlling source code
Compared to Zope , another python web application environment I’ve been fighting against, Django is a clear step forward to control your work.
First of all, the developer has the control of the source. Files are stored on the file system! It may seem an obvious assertion, but, if you have been using Zope you will know why I am so happy with that: Zope forces you to store all the code into a large binary file which acts as virtual filesystem. You cannot use a regular version control system such subversion to control your changes. …and worst, it forces you to input code in web forms!! Argh!! Django ends with such a nightmare. Files are back to the file system and to your preferred editor.
Still Django applications are modular in the same sense that Zope: you can combine several applications (modules) on a single site. For example, the administration interface is an application itself that can be used to edit any model of any installed application. You can disable it or enable it as a whole or for specific models. There is also an authentication application that can be used to transversally control the access to your application features. Every other application can use the authentication application to obtain information about validated users and to limit the access to certain features depending on the user profile. Session management and per-session storage, RSS feeds, SiteMap files, data mining interface… they all come for free, provided as applications. Besides the included applications , a nice application repository is available.
Debug cycle and exploration
Debugging your code is also very straight forward. While developing with Django, you are deploying a development Web Server not related to Apache, that you start from the console, and it is not visible from the outside. This enables each developer having her own instance of the web site. No administration passwords are needed and reloading is easier. Every message you print you’ll get it in the console so it is ideal for debugging by tracing compared to using plain mod_python which runs on the apache server and you are to monitor the apache error log. Also, when some code fails with an exception, Django constructs a very handy web page with a lot of information: the back-trace enriched with code context, parameters and local variables inspection, all the environment values, the request values… All that available in a collapsible error web page. Lately I’ve been tempted of importing a failing python code into Django just to get such a big amount of information.
Also by running ‘./manage.py shell’ you get a python shell executed in the same conditions your code will be. Indeed the ‘manage.py’ script has very useful subcommands to infer model definitions from existing databases, to see database definitions from models, to import and export test data fixtures…
The next post
So yes, Django is a mod_python with gears and a Zope without the fat. However, while I don’t regret choosing Django, it is not that perfect. On my next post, the last one on those first impressions on Django series, I will explain the problems we found while using the framework. The limitations we found and how it could be (is being) improved.
Well, maybe not the next post. Some other topics have appeared while writing this series of posts and they are likely to require an entry.