Book Review: The Definitive Guide to Django

Book Sleeve: The Definitive Guide to DjangoDjango is a framework I’ve long (in web years) held in some esteem, despite never having used it before the past few weeks. The framework’s creators’ many well reasoned contributions on all manner of debates about the web suggested a thoughtful approach, and the range of high quality sites powered by Django has kept growing, with the recent launch of EveryBlock being a prime example of its capabilities. So I was delighted to receive a copy of The Definitive Guide to django: Web Development Done Right for review.

Authored by two of the creators of Django: Adrian Holovaty and Jacob Kaplan-Moss, the book is carefully structured, initially placing django in context by exploring various approaches to web development, and then stepping through initial project creation, templates, models, url configuration, django’s famed admin interface, and so on. After eight chapters it changes tack and switches from basic tutorial to more in-depth exploration of areas like the ORM, session handling, caching and deployment. Several appendices provide supplementary material.

The first few chapters do a good job of laying out the foci of the framework’s architecture and it’s Model Template View (MTV) approach. Its pace is measured and while I wonder if it might be a little too much too soon for those totally new to full stack web frameworks, it would work well for those coming from a background building web apps with PHP, Java, or for those of us who are used to working with Rails. There are new techniques to learn and I found the book particularly useful for grasping the deeply pythonic approach, favouring flexibility over convention.

A clear example of that comes in the use of Context objects for passing values between Views and Templates. The authors initially show us the most verbose and rudimentary way to do it and gradually develop that to show how they’ve provided for various common cases. By going through those steps there’s a good chance the reader will be well equipped to work out ways to simplify their own workflow and/or create new subclasses to promote reuse in their code.

Where the book is lacking is in the examples. The introductory material, and much of the reference content is excellent, but as a newcomer to the framework I felt a little lost in how I should structure my code and how different components relate; it’s clear how models relate to the database, but how do I pass them around when building associations?

I recognise that django deliberately avoids the strong conventions of the Rails community (though even there you frequently find newcomers unsure where in the directory structure to place certain components) and there’s no need for lengthy tutorials on building a shop or how a magazine cms could work, but when I come to a book like this I’m looking for a guide to best practices at the project architecture level, not just the component level, and I was sorry not to find it. The authors clearly have a lot of experience of structuring django sites of all shapes and sizes and it would be good to learn more about how they keep those sites organised.

That said, this is a solid introduction to django for web developers; a solid contribution in a so-far underserved market and it’s likely to come in handy for a number of people. Just be prepared to supplement it with a fair amount of time in search engines working out good strategies for connecting the pieces.

Disclaimer: I was sent a copy of this book for review by the publisher. You can read it for free online or find it at apress, amazon US, amazon UK and all sorts of other places.

Tags: , , , , , , ,

2 comments

  1. Hi James,

    Thank you for sharing your thoughts about the book. Nice writeup. I’ve recently started a blog with the intention of covering all things Django, but I am particularly interested in discovering where gaps in knowledge exist from the standpoint of those new to the framework. You provide some valuable insight here.

    Cheers
    -Brian

  2. Glad you found it helpful, Brian.

    One topic I’d really like to see someone explain in detail is how to use mock objects when testing django’s models. I’ve found it a real pain to use mocks to test methods on my models without having to resort to using a test database.