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

What are templates?


The term template can have different meanings depending on what programming environment, language, or framework you are working in, so let's clarify what it represents to Django developers. In Django, a template is a string that can be combined with data to produce output. Typically, templates are stored as files on the file system, and contain placeholders that are replaced with information from the database and the results returned as HTML documents.

Understanding the need for templates

In some development platforms, such as PHP and ASP, the programming code and the HTML markup is all contained in a single file that gets processed and returned by the web server. In complex pages, this approach can become difficult to develop and maintain because there isn't a separation between the presentation and the programming logic used to render it.

Having programming logic mixed in with your markup code also limits the ability for designers to work in the files, unless they also understand the bits of programming logic sprinkled within. This makes changing the markup both tedious and time-consuming because the developer usually has to do the updates.

This clearly isn't a productive way to develop applications. We end up with a number of requirements that need to be addressed:

  • We need to separate the output markup from the Python code

  • The system should encourage reusability and maintainability of output files

  • Common page elements should be contained in their own files and easily included into the overall structure of the site

  • Designers and developers need to be able to work without getting in each other's way

  • The system should have a shallow learning curve and only require a basic understanding of programming concepts

  • The system needs to be extensible and flexible enough to fit the specific needs of our projects