Fingers crossed…
July 10th, 2008I’ve just moved my various small Django projects across to newforms-admin. So far, so good…
I’ve just moved my various small Django projects across to newforms-admin. So far, so good…
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.
James Bennett’s Practical Django Projects arrived in the post yesterday and it looks pretty good. I’ll post a proper review here later - I’m off sick today and don’t feel up to writing much
I’ve had a Flickr account for a couple of years, but haven’t done much with it until now. all that time, I’ve been accumulating more and more digital photos, initially from a small compact camera and, more recently, from a digital SLR (a Canon EOS 400D).
Over the bank holiday weekend, I finally got around to uploading a few pictures - among them the shot that you see here. I also took the opportunity to hook up this blog to my Flickr account; in fact, I’ve posted this blog entry from Flickr!
In the past, I’ve used Subversion for the one-person software development projects with which I’m often involved. Just recently, however, I thought I’d give Mercurial a spin, having heard good things about it and seen a lot of people start using it.
So far, I’m impressed - particularly by the ease with which you can clone a repository to create a new branch for development, and then merge changes made there back into the original. Another nice feature is the ability to view repository changelogs with a web browser, courtesy of Mercurial’s built-in web server. And then there’s the fact that large parts of it are written in Python…
I gave my last Secure Computing lecture today - the last ever Secure Computing lecture, as it happens - and my students prepared a little ’surprise’ for me. Halfway into the lecture, “Never Gonna Give You Up” began blaring out from beneath the lectern!
On investigating further, I discovered a notebook computer and miniature speakers, carefully concealed behind a poster. Kudos to Chris Worfolk for making it happen. Now if only he’d hacked my laptop and made that Rick Astley video appear in place of the slides…
The inexorable rise of Django continues. Packt have now published Learning Website Development with Django, which by my reckoning is the fourth Django book to make it into print - with two more due this summer from James Bennett and Paul Bissex.
Then there’s the inclusion of Django in Google App Engine. Google’s endorsement will surely do a lot to raise Django’s profile. Although many Djangonauts have expressed disappointment that some of Django’s best bits are missing from or unusable in GAE, I think it still has value as a stepping stone to using the full framework.
One of Django’s great strengths is its very active community. In addition to heavily-used newsgroups and IRC channels, there is an excellent weekly round-up podcast, the nineteenth edition of which featured some particularly enlightening stuff on internationalisation. Then there’s a host of apps out there that both demonstrate the framework in action and support its growing band of users; djangopeople.net, djangosites.org, djangofriendly.com, djangosnippets.org, djangoplugables.com are the ones that spring immediately to mind, but I’m sure there are others that I’ve forgotten to mention.
At the heart of it all are some very dedicated, hard-working core developers. It was great to see Malcolm Tredinnick’s queryset-refactor branch merged in trunk, taking us one step closer to another major release of the framework. And Jacob Kaplan-Moss continues to work at refactoring the documentation (which I’m feeling slightly guilty about, since I’d offered to help but haven’t had the time to do so, as it turns out.)
All in all, life is pretty good in Djangoland.
I’ll admit to being a little scared of Python generators when I first became aware of their existence. I was fairly sure that I didn’t understand them properly, and I failed to see how useful they really are. A few things have opened my eyes in recent months. First, Wesley Chun’s Core Python Programming helped to clarify a couple of issues, and then there was a session at SPA2008 which generated one or two “Aha!” moments, despite ultimately making my head spin.
Most recently, a few folk have blogged about David Beazley’s PyCon ‘08 presentation, Generator Tricks for Systems Programmers. I concur with the person who said it was one of the best introductions he’d come across. I particularly like the approach David’s taken, of avoiding trivial Fibonacci sequence examples and jumping straight into real problems of the kind faced by sysadmins. The performance stats he’s gathered are striking; I hadn’t realised just how competitive writing generator-based scripts for log file analysis can be with non-generator approaches or the more traditional tools used for this purpose, such as awk.
All this has made me more determined to make much better use of generators in my day-to-day Python programming.