Jeff Croft

I’m a product designer in Seattle, WA. I lead Design at a stealthy startup. I recently worked at Simply Measured, and previously co-founded Lendle.

Some of my past clients include Facebook, Microsoft, Yahoo!, and the University of Washington.

I’ve authored two books on web and interactive design and spoken at dozens of conferences around the world.

But seriously, who gives a shit?

Blog entry // 02.21.2006 // 9:06 PM // 10 Comments

Django Templates: An Introduction

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:

  1. 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.
  2. 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.
  3. 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 <b> and <i> tags are deprecated.
  4. Programmers can add to and change the application code without affecting the display.

Django template code for a weather app

(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 if...then statements, 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.

Django's auto-generated models documention for a weather app

At World Online, our workflow is very much based on this model. Itâs not uncommon for Matt or Jacob to say the following to me several times per day: âOkay, such-and-such-app is ready. Go make it look pretty.â They can move on to the next item on their to-do list. I look up the appâs model documentation in Django’s admin module and start cranking away on its presentation. Itâs really quite efficient. In the end, Django templates are for designers and front-end XHTML/CSS/Javascript types. Theyâre not for programmers, and theyâre built as such.

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!

Comments

  1. 001 // Sean S // 02.21.2006 // 10:01 PM

    Whoa, seriously interesting. But how do you pronounce the darn thing?

  2. 002 // Jeff Croft // 02.21.2006 // 10:15 PM

    Sean-

    From the Django FAQ:

    “What does “Django” mean, and how do you pronounce it? Django is named after Django Reinhardt, a gypsy jazz guitarist from the 1930s to early 1950s. To this day, he’s considered one of the best guitarists of all time. Listen to his music. You’ll like it. According to Wikipedia, “Django is pronounced zhane-go (with a long ‘a’).”

    That having been said, through both my jazz studies in college and my time at World Online, I’ve never heard anyone pronounce it that way. Everyone says: JANG-go. Basically like it looks, but with a silent “D”.

  3. 003 // Yannick // 02.21.2006 // 10:24 PM

    It’s good to see this article pop up about Django. I have been looking at it a bit recently and even tried the little tutorial by Adrian. It looks interesting.

    I look forward to hearing more about Django and the templating system Jeff.

  4. 004 // Brad Daily // 02.21.2006 // 10:36 PM

    I am one of those ruby tinted glasses fellas, but I can relate to being new to the world of template systems, as I never really used them in my PHP apps.

    Although Rails does not ship with a templating system, there are some good ones out there. I recently have fallen in love with Markaby.

    For instance:

    ul do   li ‘One’   li ‘Two’ end

    Will create a list. The thing I like about this is it makes the entire thing ruby, which makes it a little easier for me to sift through.

    Look forward to hearing more about Django from you Jeff!

  5. 005 // Jeff Croft // 02.21.2006 // 10:43 PM

    Brad-

    Thanks for the comment! Markaby looks like a cool little language for a Ruby person.

    The thing I like about this is it makes the entire thing ruby, which makes it a little easier for me to sift through.

    I’m afraid that’s probably exactly what I wouldn’t like about it. Being a non-programmer, I like that Django’s template language is aimed at me. It doesn’t require me to understand Python (or Ruby) syntax at all.

    I can see how a Ruby programmer who was building an app all by themselves may like having a Ruby-like template language, but that’s not me. :)

    Two other things I probably should have noted in the original post, but failed to:

    1. Django’s architechiture is very loosey-coupled. As such, it is possible to use template languages other than the Django template language with Django. With a little work, one could probably even plug your Markaby into Django. :) Similarly, it is theoretically possible to use the Django template language on top of another system besides Django.
    2. Django’s template language is not limited to HTML (a quick look at Markaby suggests it may be?). Using the Django template language, you can create any text-based file format, from XHTML to CSS, to Javascript to XML to e-mail, to…well, you name it.
  6. 006 // Victoria Pavlova // 02.22.2006 // 3:50 AM

    Wonderful start, I must say. Really interesting ‘cause I am a designer who does not like to deal with programming languages (mostly due to the fact that I studied to be a programmer :-) ). It’s a pity that here, back home in Ukraine, nobody uses Python or Ruby and so on.

  7. 007 // Brad Daily // 02.22.2006 // 8:32 AM
    I’m afraid that’s probably exactly what I wouldn’t like about it. Being a non-programmer, I like that Django’s template language is aimed at me. It doesn’t require me to understand Python (or Ruby) syntax at all.

    I hear ya, and can definitely see the advantages of this sort of templating system to designers. In fact, a Django inspired templating system called Liquid is now available for rails, with very similiar syntax.

    Django’s template language is not limited to HTML (a quick look at Markaby suggests it may be?). Using the Django template language, you can create any text-based file format, from XHTML to CSS, to Javascript to XML to e-mail, to’¦well, you name it.

    You can use markaby for email templating within Rails’ ActionMailer class (for both HTML and plain text), but outside of that, you’re right, it is really an (X)HTML thing (as I understand it anyway).

  8. 008 // Wilson Miner // 02.22.2006 // 9:48 AM
    In short, this means no more cleaning up after your programmer, who doesn’t seem to know that the <b> and <i> tags are deprecated.

    I don’t know what kind of programmers you’ve been working with, but nobody I know would dream of such a thing. Technically though, <b> and <i> aren’t deprecated if you’re using an HTML 4 doctype.

    Nice writeup - I’ve been meaning to write something along these lines for a long time, but you beat me to the punch. Serves me write for putting it off.

  9. 009 // John Heasly // 06.05.2006 // 5:04 PM

    Today (6/5/06, 3:13 p.m. Pacific) when requesting the page http://www2.jeffcroft.com/2006/f… using Firefox 1.5.0.4 on OS X there is some resource at php.jeffcroft.com (all that shows in the Firefox status bar is “Waiting for php.jeffcroft.com… ” so I can’t say for sure what’s holding up the show.) that never loads and hangs the window. Works okay on Safari though.

  10. 010 // akaihola // 12.26.2006 // 1:23 AM

    Re the procunciation of “Django”, I regret that I didn’t listen carefully when I watched a TV documentary about Reinhardt the other day (a Canadian guy visited his home town and talked to his relatives).

    American musicians might very well pronounce it wrong, and the original French-speaking pronunciation could really sound like “zhane-go” (actually, I’d assume “zhane-goh” would be a closer approximation). I’m not sure though.

    In any case, our typical Finnish way to pronounce it (“dyangoh”) is probably wrong :)