Within the first few hours of my new job at World Online, I was tossed into the unfamiliar land of Django templates. In fact, the idea of using a template language at all was mostly new to me. Sure, Iâve poked at Moveable Type templates here on this site, but Iâd never used anything on the level of Django’s templates before. A month later, Iâm extremely impressed with the system. It lets me do everything I need to do without my having to learn to be a programmer — and a not-trying-to-fumble-over-a-programming-language-Jeff is a happy Jeff. As such, I thought Iâd start a series of posts here on jeffcroft.com highlighting some of my favorite features of the Django template language…
…but not in this entry. :)
Instead, in this introductory post, I want to tell you a bit about the culture and background of Django, so that you might understand why it includes a template language, who the template language is for, and — perhaps more importantly — who itâs not for.
For those wearing ruby-tinted glasses with blinders on either side, Django is a Python-based web framework for rapid application development. It was developed at World Online in Lawrence, KS over two years ago and was released as open source software last summer. Django originates from a real-world situation. A few years back, Adrian Holovaty and Simon Willison (both of whom were working at World Online at the time) started working on a CMS and web platform for lawrence.com, an exhaustive site that covers Lawrenceâs local music and nightlife scene. Eventually World Online transitioned all of our sites to the new platform theyâd developed. That platform was ultimately split into two separate projects: Django, the core framework upon which applications are built, and Ellington, a suite of Django apps that covers just about everything youâd ever want to do on a news website (Django is open source, Ellington is a commercial product). Although it has been in use on several high-traffic and award-winning sites for a couple of years now, Django is officially at version 0.91, with 1.0 to be released in the coming months.
By the time Django was publicly released, Rails had begun to gain a good deal of traction in the web community. As such, Django is sometimes referred to by observers as âRails for Python.â While there are a lot of similarities between Django and Rails, there are also a lot of differences (if youâre interested in more details on how Django compares to Rails, I suggest you check out the Snakes and Rubies video, which has great presentations by Django co-creator Holovaty and Rails creator David Heinemeier Hansson).
One major difference is that Django includes a template language, whereas Rails does not. One of the core reasons for Django’s inclusion of a template language is to separate application and business logic from presentation. There are several advantages to this philosophy, most of which stem from the resulting separation of designer and programmer. Consider:
- Designers canât break the application. Since they never touch the application code, there is no worry that a mistake by the designer is going to bring your app to a crashing halt.
- Designers have complete control to do literally anything they want with the content — and they can do it without having to bother the programmer at all.
- Programmers arenât futzing with an applicationâs design and front-end code. In short, this means no more cleaning up after your programmer, who doesnât seem to know that the
<i>tags are deprecated.
- Programmers can add to and change the application code without affecting the display.
(It should be mentioned that templates can (and usually do) include presentational logic (but not application logic). Besides variables, the Django template system allows for basic logical tags, including
for loops, etc.)
One clever thing Django does auto-magically is build documentation about your application for you. Seriously. When programmers build models for their applications, pages are auto-generated in Djangoâs admin module that define all of the various objects and attributes template designers can get at. This makes the hand-off of an app from the programmer to a designer very painless.
In the coming installments, Iâll attempt to get into more detail on individual features and components of templates. I tentatively plan to cover the most powerful feature of Django templates first: inheritance. Stay tuned!