LWN.net Logo

Django nears 1.0 milestone

By Jake Edge
August 27, 2008

The Django web application framework is nearing an important milestone: version 1.0. Like Ruby on Rails, TurboGears, and others, Django is meant to streamline application development for the web by providing easy-to-use libraries for tasks that are commonly performed by dynamic web sites, such as database access and HTML templating. The Django project has just released the second beta of the 1.0 release, with the final release due in early September.

[Django Logo]

Django is Python-based, with an eye towards getting an application—or the beginnings of one—up and running quickly. The framework is quite "Pythonic", so it will be very accessible to those used to programming in that language. Django also has an extensive set of documentation including an on-line (and dead tree) book.

While Django can be used to build nearly any kind of web site, it has a "sweet spot" that is well described in the introduction to The Django Book:

Because Django was born in a news environment, it offers several features (particularly its admin interface, covered in Chapter 6) that are particularly well suited for "content" sites – sites like eBay, craigslist.org, and washingtonpost.com that offer dynamic, database-driven information. (Don't let that turn you off, though – although Django is particularly good for developing those sorts of sites, that doesn't preclude it from being an effective tool for building any sort of dynamic Web site. There's a difference between being particularly effective at something and being ineffective at other things.)

The database abstraction (or model) layer is at the heart of what Django provides to a programmer. Most dynamic web sites use some kind of database, so Django supports multiple, popular database systems, of both free software and commercial varieties. Because the model layer is a high-level description of the data, moving from one database backend to another is greatly simplified. In addition, the flexibility of the model API means that many applications can do all of the queries that they need without ever descending into SQL—though the facility is there if it is needed.

An example taken from the book nicely illustrates the simplicity of Django's model API:

    class Book(models.Model):
	name = models.CharField(maxlength=50)
	pub_date = models.DateField()
From this information, along with some configuration concerning database type and name, Django can generate and execute the appropriate SQL to build a database table to store a Book. As fields get added and removed from the model, the proper commands to synchronize the model and the database can be generated. From application code (i.e. the "view" code), then, models can be used in various ways, for instance:
    def latest_books(request):
	book_list = Book.objects.order_by('-pub_date')[:10]
	return render_to_response('latest_books.html', {'book_list': book_list})
This can then be used in an HTML template as follows:
    <h1>Books</h1>
    <ul>
    {% for book in book_list %}
    <li>{{ book.name }}</li>
    {% endfor %}
    </ul>

That is, of course, a simple example, (and it lacks the URL mapping piece) but it gives a flavor of the power that Django provides. It is also an example that most folks, even non-programmers, can follow to some extent. Like many model-view-controller (MVC) based frameworks, Django splits up the various pieces of functionality in an attempt to break the coupling between the user interface, "business" logic, and data storage, allowing each to be worked on separately. In particular, the template language is meant to be used by web page designers who have little programming background.

One of the nicer features is the automatically generated administrative interface. Many web frameworks have incorporated an easy way for a site administrator to start entering data into their models. This allows developers to get their application running quickly with real data without having to code up a bunch of tedious data entry forms. One of the bigger changes from the current 0.96 Django release and the upcoming 1.0 is a complete overhaul of this interface.

Many developers have been using the development versions of Django from the subversion repository because the released version (which is what is packaged by distributions) has lagged. There are a number of backward-incompatible changes since 0.96 and the documentation is geared towards the 1.0 version (though it should be noted that versions for each of the last two releases are also readily available). Stabilizing the API has been the driving force behind the 1.0 release. Going forward, compatibility will be maintained unless a security or other serious problem is found.

Django has numerous other interesting features: authentication, session handling, and a caching system that is geared towards scalability. It is also fully ready for internationalization, with "full support for multi-language applications, letting you specify translation strings and providing hooks for language-specific functionality."

Due to be released on September 2, just in time for DjangoCon, 1.0 is, unsurprisingly, both feature and "string" frozen—only serious bug fixes are still going in. Like other projects, including Python itself, Django is "governed" by an independent foundation; the newly formed Django Software Foundation in this case. The original developers of Django are still active both as foundation board members and as active developers (and users) of Django.

There are lots of web frameworks to choose from, in nearly every computer language used today—though none for COBOL as far as we have heard—so Django is just "yet another" web framework at some level. Django does have some things going for it that others may lack: a development community that is active and uses the framework (generally the development version checked out of the subversion repository) for live, high-volume sites, excellent documentation, and a well thought-out design. For anyone looking for a Python-based web application framework, at least taking Django for a spin will be time well spent.


(Log in to post comments)

Django nears 1.0 milestone

Posted Aug 28, 2008 7:54 UTC (Thu) by Velmont (guest, #46433) [Link]

I put down the book «Practical Django Projects» to read this article. I've read the Django Book online, -- but I needed something more project oriented. And I've heard that this book is that. So far it's been very good!

Django does have a lot of promise. I will be happy to migrate away from PHP. CakePHP and other frameworks never floated my boat, but Django does seem much easier. :-)

Django nears 1.0 milestone

Posted Aug 28, 2008 11:49 UTC (Thu) by maney (subscriber, #12630) [Link]

As fields get added and removed from the model, the proper commands to synchronize the model and the database can be generated.

As far as I'm aware, this remains a wishlist item. Last time I checked, there was a framework for applying updates, but at least for non-trivial changes you had to implement the actual update code. And non-trivial would include adding a column if there's no reasonable default value... (that's for updating existing tables with valuable data already present. if just dumping the table and rebuilding it anew will do, as it often the case during early development, then Django's got you covered.)

There's a great deal to like about Django (and that's why I've been using it more and more over the three years since it was released), but it isn't yet a magic wand. In fact one of the things that delayed 1.0 was a major restructuring that aimed at removing the magic! :-)

I have come to particularly appreciate Django's templates. After getting used to their capabilities and limitations, I've come to see that those are carefully designed to, in nearly all common uses at least, encourage you to sensibly put the data marshalling logic into the view code and the presentational aspects into the template (including sometimes custom filters and tags). Even though I'm usually the architect, coder, web designer, and chief bottle washer, and so wouldn't seem to have much need for a clean separation there (and I used to glory in that, having worked with early PHP and Quixote, mostly, in the past), I find that it has some real benefits once you get used to it. Django's templates don't force you into this, but they do a good job of reminding you (by feeling strained) when it's time to take a step back and think about why that's happening. The result is usually a better division of work between view and template, IME.

While I'm at it, I want to add a resounding you got that right to the earlier praise of Practical Django Projects. Great book that has made many things I've had a fuzzy notion of for years crystal clear - now I want to overhaul a bunch of old projects to bring them into line! Maybe someday I'll have the tuits for that...

Django nears 1.0 milestone

Posted Sep 4, 2008 6:43 UTC (Thu) by muwlgr (guest, #35359) [Link]

Django uses a separate language for html templates. While in RoR, the language is the same as main: embedded Ruby (erb). Simpler. But may be Django template language does have better features about which I don't know.

COBOL

Posted Aug 28, 2008 15:57 UTC (Thu) by rfunk (subscriber, #4054) [Link]

What, you've never heard of COBOL ON COGS?! ;-)

COBOL

Posted Aug 29, 2008 0:57 UTC (Fri) by njs (guest, #40338) [Link]

That's a great joke :-)

You know what else is funny? COBOL support in ASP.NET!: http://www.c-sharpcorner.com/UploadFile/nrsurapaneni/4MSN...

COBOL

Posted Aug 29, 2008 14:07 UTC (Fri) by holstein (subscriber, #6122) [Link]

There is also the seductive CobolScript.

COBOL

Posted Sep 3, 2008 9:08 UTC (Wed) by pdundas (subscriber, #15203) [Link]

I'm waiting for the object oriented ADD 1 TO COBOL GIVING COBOL...

Django nears 1.0 milestone

Posted Aug 28, 2008 21:42 UTC (Thu) by moreati (guest, #5715) [Link]

<blatent plug>For those of us in the UK, who can't make the US release party, we'll be celebrating at PyCon UK on 12-14th September (2 weeks time) in Birmingham.

http://pyconuk.org </blatent plug>

Hope that wasn't too off topic. Alex.

New and improved docs

Posted Aug 29, 2008 16:18 UTC (Fri) by tekNico (guest, #22) [Link]

Speaking of documentation, check out the refactored one that will be included in v.1.0 .

maxlength is now max_length

Posted Sep 8, 2008 23:26 UTC (Mon) by nealmcb (subscriber, #20740) [Link]

Yes - django is a wonderful project - both great code and a great community.

Beware - as noted in the comments on the sample code you copied, the maxlength parameter was renamed max_length before the API freeze for 1.0, so it would be more consistent. A bit of a pain now, but over time it will save a lot of people a lot of hassle. See more tips for updating old code at:

http://docs.djangoproject.com/en/dev/releases/1.0-porting...

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds