Review: Practical Django Projects

James Bennett’s Practical Django Projects is, by my count, the fifth book on Django to make it into print, but it is distinctly different from its predecessors.

The best of those predecessors, Adrian Holovaty’s and Jacob Kaplan Moss’ The Definitive Guide to Django (also published by Apress) continues to serve both as a reference and as an excellent introduction to the framework, detailing the philosophy behind Django and explaining how it differs from its rivals. However, The Definitive Guide is very much a ‘bottom-up’ book, exploring each of Django’s components individually by means of small examples. James has, interestingly, adopted the complete opposite approach in Practical Django Projects. The result is a book that complements The Definitive Guide superbly. This is essential reading for anyone wishing to step up from merely experimenting with Django to actually doing serious work with it.

Early Material

James’ approach is to guide the reader through the construction process for three realistic web applications: a simple CMS, a fully-featured blog and a site for uploading and rating code snippets. The first of these examples is the smallest, spanning Chapters 2 and 3 of the book. This example serves partly as a very basic introduction to key features of the framework - project configuration, the admin app, views, templates and models - and partly as a powerful demonstration of how a genuinely useful application can be constructed mainly from components already present in Django (in this case, the admin and flatpages apps), with barely any additional code.

James doesn’t leave it at that; in what is to be a recurring theme of the book, he makes his CMS more useful and interesting by also incorporating a third-party component - in this case, the TinyMCE JavaScript rich text editor, which is used in a customised admin template to enhance flatpage editing.

The Blog Example

The book is dominated by the second example app, a blog, which is developed over the course of the next four chapters. The basic data models, templates, view code and URL configuration needed to deal with blog entries are discussed in detail in the first of these chapters. This chapter also demonstrates the value of generic views and explains how to decouple an app’s URL configuration from that of the project that hosts it.

Subsequent chapters introduce the concepts of data model managers, template inheritance, custom template tags and Django’s signals mechanism. James very sensibly avoids covering every last detail of these advanced features; after all, you can go to The Definitive Guide or the excellent built-in/online documentation for that. The important thing is that these features are introduced in the context of a real application, making it much easier to appreciate the benefits that they bring.

Once again, James takes the opportunity to demonstrate how third-party components can be used to enhance an application - in this case, providing the ability to write entries using Markdown syntax, submit blog links to del.icio.us and filter comment spam using Akismet. The final version of the blog even has the ability to generate Atom feeds for links and entries that have been posted to it. It really is a fully-featured application, lacking only the CSS and JavaScript required for a professional look and feel. (A suitable stylesheet is supposed to be available from the Apress website, along with all of the source code described in the book, but this material wasn’t available at the time of writing this review.)

The Last Four Chapters

The final example app reinforces the techniques discussed in earlier chapters. Further advanced features of Django are also introduced - notably the customisation of ORM queries with extra SQL and the development of more complex template tags that have to parse ahead in a template - but the app serves mainly as a vehicle for introducing Django’s form processing capabilities. James gives a very thorough explanation of form validation here, which may clarify things considerably for less experienced Djangonauts.

The last chapter of the book is in some ways the most valuable of all. In it, James takes a step back from the code to provide general advice on how you can make it easier to reuse apps in other projects. Readers of his blog will have come across some of his advice before, but it is useful to see all of this material collated, expanded and on the printed page.

Conclusions

Practical Django Projects is a valuable addition to the growing library of books on the world’s best web application development framework. It isn’t a work of reference, but it is an excellent and detailed guide to the construction of flexible and reusable apps that make effective use of Django’s extensive capabilities. It could certainly serve as a good, top-down introduction to Django for someone with a background in other web frameworks and some prior experience of Python, although it isn’t a replacement for the more detailed exposition of Django design principles to be found in The Definitive Guide to Django.

No book is perfect, and this one has a few minor problems. There is the odd typo to be found in the text and the code examples which could trip you up if you are working through the example apps, and the use of third-party components needs to be explained a little more carefully, particularly with regard to which versions are required. (For example, I found out the hard way that the existing version of the markdown library on my Ubuntu machine wasn’t compatible with the blog app.) However, these minor flaws detract little from what is the new ‘must-have’ purchase for the beginner- to intermediate-level Django developer.

4 Responses to “Review: Practical Django Projects”

  1. David Grant Says:

    I just got this book in the mail and I’m looking forward to digging into it.

    Is http://djangobook.com/en/1.0/ the same as The Definitive Guide to Django?

  2. David Grant Says:

    Sorry I just answered my own question…yes they are the same.

  3. Allan Says:

    I’ve been working through the book, but have been having trouble getting the TinyMCE example in Chaper 3 to work.

    I don’t suppose you have the source code for this chapter? It looks as if the code still isn’t up on the Apress site.

  4. Nick Says:

    I’ve probably got it somewhere; I’ll have a look…

Leave a Reply