Template Language Review

First, let’s quickly review a number of terms introduced in earlier chapter:

  •  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 or for 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 }}:
    My first name is {{ first_name }}. My last name is {{ last_name }}.
  • 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 the variable “holes” with values from the context and executing all template tags.

The rest of this chapter discusses ways of extending the template engine. First, though, let’s take a quick look at a few internals left out earlier.

Back to Tutorial

Extending the Template Engine
RequestContext and Context Processors

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?