A comprehensive, practical exploration of the usage and customization of Django's template system, including tutorials on pagination, caching, and internationalization. This book is for web developers and template authors who want to fully understand and utilize the Django template system. The reader should have completed the introductory tutorials on the Django project's website and some experience with the framework will be very helpful. Basic knowledge of Python and HTML is assumed.
If you have ever looked for a book on the subject of Django templates, then a five minute search on the web will soon tell you that they are far and few between. In fact, you’ll most likely find that Django templating usually has a treatment taking up no more than a couple of chapters in an otherwise lightly related book.
Django 1.0 Template Development is virtually one of a kind on its subject matter and, therefore, necessarily covers the subject in sufficient breadth and depth. On that strength alone, the book should probably hold its place on any template author or web developer’s bookshelf for some time to come.
The book purports to have its audience as web developers and template authors looking to leverage all the qualities provided by such a complete templating system as Django (version 1.0). It also assumes that the reader has completed some of the introductory tutorials on the Django project web site, as well as having a basic level of Python and HTML experience.
The book is built, as indeed are most, around a small set of sample applications that grows as the book progresses through the chapters. It starts with an introduction to the template system, covering the many advantages of using templates, such as modularity, flexibility and accessible syntax. It also mentions some limitations, which are covered in more detail later in the book, and what some of Django’s critics have to say. The next couple of chapters breeze through how views are set up, how URLs are configured, what generic templates are, and finally the uses of context data.
Chapter 4 is curious in that it is a selected skim through the online Django documentation page on built-in template tags and filters: one would normally expect to find this in an appendix. Interestingly, on some of the entries it reduces considerably what is written in the online documentation. Conversely, the treatment of other entries is more verbose. There’s no doubt that having a reference to hand on paper like this is a bonus – I found myself looking to it time and time again. On the other hand, some may come back to the old programmer’s adage – ‘you can’t grep dead trees’.
Chapter 5 jumps back into the sample applications with a reasonably in-depth look at Django’s take on template loading and inheritance. Chapter 6 sets the book apart from many other web development books I have read over the years, in the way that it considers a web application to be accessible from a variety of web browsing platforms, not just a pc and a browser. It takes a look at different approaches to using Django to serve multiple templates for different platforms, including mobile devices and how to create site themes.
Continuing with the ever growing set of sample applications, Chapter 7 takes the reader into the very interesting, but potentially complex, subject area of custom tags and filters. If there is a case for having a reasonable amount of Python knowledge to hand before starting, then it is in this chapter where it becomes evident.
Every web developer’s bread and butter, pagination, is the main subject of Chapter 8. Typically, Django undertakes pagination effortlessly and so the book has time to cover other issues around the paging of records such as how to prevent orphaned records and looking at database performance.
Chapter 9 shows the reader how the look and feel of Django’s excellent admin interface can be changed in a few simple steps. There is no exploration of how to change functionality in the admin interface; it is made clear that there is plenty of online documentation on how to do that – indeed that would deserve a book all of its own.
Chapter 10 investigates Django’s template caching framework, why one might need to use it and different caching strategies, such as per-view caching, automatic site wide caching and working with other cache systems. Chapter 11 is a brief look at another of Django’s strengths, internationalisation. At this point the reader starts one last sample application and completes some basic