Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

Breaking templates into reusable pieces


Up to this point, we have been working with template files that were self-contained. This was good for explaining the theory behind working with templates, but in reality your templates will share common parts with each other such as headers, footers, and menus.

Typically, in web application development (regardless of the language or platform) this is solved by dynamically inserting other files into your template (known as "include" files in many systems). When a template is loaded, it "calls in" content from various files and inserts it in the appropriate places. This approach does not lend itself well to complex setups where your included file needs to inject content into multiple places in your base template. (It can be done, but it's typically not very simple.)

Django gives us a very flexible way to break up our templates, which solves the challenges of complex include files, called template inheritance. Instead of filling holes in your base template...