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

Built-in tag reference


Tags can be trickier to understand than filters because they can do so much more. Tags allow for programming logic in your template code, such as looping through records with the {% for %} tag and performing conditional logic with the {% ifequal %} tag. If you're unsure whether to use a tag or a filter, think about what you're trying to accomplish. If it's simple display formatting, you'll probably use a filter; if it's something more involved, you'll probably need a tag.

To use a tag, you put a single bracket and percent symbol around the tag name. Many tags require an ending tag, such as the ifequal/endifequal tag in this example:

{% ifequal object.color 'blue' %}
   The object is blue.
{% else %}
  The object is not blue 
{% endifequal %}

autoescape

This turns on or off the auto-escaping behavior in a Django template block. When escaping is enabled, HTML characters are turned into their character equivalents to prevent potentially malicious content from being written...