Book Review: Pro Django

Published 15th March 2009

Pro Django Book Cover

Pro Django is a book for developers who want to deepen their knowledge of how Django works.

Content

After the first chapter explains the fundamental design philosophies, the second chapter ("Django is Python") explicates important Python techniques the framework relies on. Metaclasses, Augmenting Functions or Descriptors are some of them.

They are explained clearly and with a lot of understandable code examples. Take Metaclasses for example. The book explains them by using Django's declarative syntax as a sample. I find that by knowing how Django uses them it's much easier to understand Metaclasses, as I now have a good practical example to refer to.

The following chapters go into modules of the framework, which are "Models", "URLs and Views", "Forms", "Templates" and "HTTP". The basics from the official documentation are skipped or just briefly mentioned as this book goes into more depth.

Parsing the content of a template is a good example for this. The book does an excellent job explaining every single step of how a raw string is processed through the Lexer and Parser to a set of Python objects that can be rendered. I always wondered about nodes and tokens when writing template tags. After reading the chapter about templates I finally understood the whole process and can now think of even more possible uses.

Chapter 8 ("Backend Protocols") describes Django's generic API for features like databases, authentication or storage. By implementing the protocol of an API it's easy to write backends that, for example, can enable Django to use another database engine or use another storage backend (like Amazon S3).

Next, the "Common Tools" chapter shows lesser known tools and features of Django. It explains which core exception should be thrown in which situation, the data structures which are available (MergeDict, MultiValueDict, SortedDict) and other interesting things which help keeping the code consistent and easier to maintain.

The last two chapters "Coordinating Applications" and "Enhancing Applications" go step-by-step through the process of creating a Real Estate project and enhancing it using the techniques described in this book. The latter chapter made me realize how handy all the previously explained low level methods are when developing reuseable 3rd party applications for Django. It enables a model to keep historical records of its contents by adding just a single line to the original application.

Conclusion

Overall I found this book to be a great read. I will keep it around as a reference for further development and recommend it to every Django developer who wants to take a look behind the scenes of Django.

Since the book was written for Django 1.0 I think that some people are holding back on buying it because of the Django 1.1 release. But there's no need to worry. Backwards-incompatible changes will not happen in the 1.x branch and the API will remain stable until Django 2.0. This book should be safe to use with every Django 1.x release.