First, let's quickly review a number of terms introduced in Chapter 3, Templates:
A template is a text document, or a normal Python string, that is marked up using the Django template language. A template can contain template tags and variables.
A template tag is a symbol within a template that does something. This definition is deliberately vague. For example, a template tag can produce content, serve as a control structure (an
if
statement orfor
loop), grab content from a database, or enable access to other template tags.
Template tags are surrounded by {%
and %}
:
{% if is_logged_in %} Thanks for logging in! {% else %} Please log in. {% endif %}
A variable is a symbol within a template that outputs a value.
Variable tags are surrounded by
{{
and}}
:A context is a
name->value
mapping (similar to a Python dictionary) that is passed to a template.A template renders a context by replacing...