The template language

When a developer develops templates, he/she regularly needs to use the template language and filters.

Template tags

The following are the key elements of the template language:

  • {% autoescape on OR off %} {% endautoescape %}: This automatically starts the auto-escape feature that helps protect the browser of the displayed data (XSS).
  • {% block block_name %} {% endblock %}: This sets the blocks that can be filled by templates that inherit from them.
  • {% comment %} {% endcomment %}: This sets a comment that will not be sent to the user as HTML.
  • {% extends template_name %}: This overrides a template.
  • {% spaceless %}: This removes all the whitespaces between the HTML tags.
  • {% include template_name %}: This includes a template named template_name ...

Get Django: Web Development with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.