eriksmartt.com>Selected Archives

The Definitive Guide to Django

Last week I received a review-copy of the new "The Definitive Guide to Django" book from Apress. I hadn't planned on buying the book since it seemed a little too beginner-focused; but I agreed to give it an honest reading, so I happily dove in with an "it's Python—of course I'm going to like it" attitude.

Background

The book was written by Adrian Holovaty and Jacob Kaplan-Moss, the creators and "Benevolent Dictators" of the Django Web Framework. It was Holovaty and Kaplan-Moss' first book, and, I believe, meant to be the first Django book to market. The book was drafted online; open to peer-review and community feedback; and ultimately published under the GNU Free Documentation License.

From the get-go, the print edition had a few inherent market challenges to face: First, the entire book is available online, for free, at: <http://www.djangobook.com/>. Second, in many ways the book is a re-hash of the docs available at <http://www.djangoproject.com/documentation/>, which are also free. Third, the book covers Django 0.96, not SVN. (0.96 is technically the latest-snapshot release, but a lot has changed since 0.96.) And finally, the $45 MSRP could be seen as a little steep for what is effectively a printed copy of a free, online book.

The print experience

Diving in, the book takes the reader through the basic installation process, provides a brief background on how the framework came to be (and why you want one) then steps through the major features (ie., the template system, ORM, URLconfs, generic views, etc.) It's what you'd expect from a technical reference no fluff, and straight to the details. There are plenty of code snippets to learn from, and the sidebar notes tend to be insightful.

Since it wasn't new material for me, the book was a fairly quick read; but the experience of reading Django documentation in book-form was actually quite fascinating. There's something about settling into a comfortable chair with a book, pen, and highlighter that you just can't get with online documentation. Perhaps it was just a little more noticeable given the material. When I read the Django docs online, I tend to skim over them while trying to solve a problem. I use them as a reference more then a learning tool, and it's usually while actively coding, thus my brain is partially distracted with whatever it is I'm building.

With a physical book, you can unplug, step away from the computer, and give the material your undivided attention. This isolation from distraction results in a much deeper understanding of the text. This is the real the value of the printed book—it's an opportunity to digest online documentation in an environment more conducive to learning and retention.

My general take-aways and observations

  • The book definitely has a beginner/intermediate feel to it, but only in the sense of a beginner Django user — not a beginner Web developer or Python programmer. I'm curious how well the book is received by folks who are beginners at Django and dynamic Web development since the text brings up a lot of complex topics in Web development that aren't really explained. (Ex., database administration, server clustering, manipulating HTTP headers, etc.)
  • The breadth of the book is impressive, but in some ways, the book really feeds you through a firehose, so to speak. It throws a lot of new concepts at the reader and doesn't always explain why you'd need to know them, or how you might use them in the real world. For someone deploying a site with Django, it will be good to know that all these features are available, but it might take awhile before they need to use them (if ever.)
  • The book does touch on some of the more advanced Django features (like extending the template system and writing custom middleware) which was nice, but some topics are reserved for the appendix and get limited coverage (ex., model managers and 'Q' queries.) Others, like the Sites Framework, are given good exposure, but not so much that the reader is left with a clear picture on when to use them and what their limitations are.
  • The forms processing chapter was a bit lighter then what I was hoping for -- especially given that the current newforms documentation still trends toward "read the source code." It provides enough to start using newforms if your form needs are pretty basic, but doesn't address creating your own widgets, or any of the fun stuff you can do once you start dynamically generating and manipulating newforms objects.
  • It might have been nicer if the examples in the book were a little more tied together, perhaps all focused on building a single example project and showing how the various features are used in real-world applications. (The example of the book-publisher's app was a reoccurring theme, but not so strongly that each chapter applied it's new learnings to it.)
  • The Deploying Django: "Going Big" sub-section provides a nice infrastructure graphics for how high-traffic systems might be setup, but once you get to the point of being "big", you need to architect for it, and that's really outside of the scope of this book. For this section, it might have been nice to reference other resources on scaling infrastructure, and perhaps pointing out some of the ways that Django can be optimized for performance and horizontal scaling. (For example, one of the Django projects we put into production at work will happily support 1,200 requests/second, but the database layer and session middleware have been reworked a bit, and the content caching approach is a little different then the standard Django offering.)
  • On the more positive side, even as someone who's been using Django for some time, I still learned a few new tricks, and I was reminded of a few features that I could be taking better advantage of. (And when you do this stuff professionally, every shortcut and productivity gain has monetary value — avoiding even a half-hour of debugging pays for the cost of this book.)
  • This book would make a fantastic read for a back-end developer joining a project that is already using Django. I normally tell new developers to go through the Python Tutorial at <http://python.org/doc/tut/> if they're new to Python, then to complete the Django Tutorials at <http://www.djangoproject.com/documentation/> before trying to grok any in-progress Django project. Now I have a third reference (though I might still suggest that they walk through the tutorials first, so that they have some context when reading the book. Otherwise, there are just too many new concepts to do a straight read-through and still grasp it all.)

Summary

The market needed a good Django book, and this one delivered a solid reference for the framework. Arguably, it's not really a "Beginner's Guide to Django", but hopefully it covers enough of the basics that future books can focus on best practices and more advanced techniques. (On a related note, there's apparently an upcoming "Practical Django Projects" book, also from Apress, that will focus more on building "reusable Django applications from start to finish". This might actually make for a better beginner's book, depending on how it turns out. [Via The B-List: Speaking and writing].)

The million-dollar question then, is "Should you buy this book?" My answer ended up being a bit more positive then I expected, but there are two parts: First, if you're a front-end developer only, you don't need this book. You can just read Chapter 4: The Django Template System online, and then use the "Django Templates: Guide for HTML authors" section of the online docs as a reference. For back-end developers, the story is different. If you're going to just "read it while you hack", then you might as well just read it online; but if you're serious about building applications with Django (especially if you're new to it) then you should consider the book and investing the time to step away from the computer and really let yourself get into it. Unless you are an active contributor to Django (which I'm not, just to be clear) the odds are pretty good that you'll learn something new, even if you're already using Django today.