templates.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. =========
  2. Templates
  3. =========
  4. .. module:: django.template
  5. :synopsis: Django's template system
  6. Being a web framework, Django needs a convenient way to generate HTML
  7. dynamically. The most common approach relies on templates. A template contains
  8. the static parts of the desired HTML output as well as some special syntax
  9. describing how dynamic content will be inserted. For a hands-on example of
  10. creating HTML pages with templates, see :doc:`Tutorial 3 </intro/tutorial03>`.
  11. A Django project can be configured with one or several template engines (or
  12. even zero if you don't use templates). Django ships built-in backends for its
  13. own template system, creatively called the Django template language (DTL), and
  14. for the popular alternative Jinja2_. Backends for other template languages may
  15. be available from third-parties. You can also write your own custom backend,
  16. see :doc:`Custom template backend </howto/custom-template-backend>`
  17. Django defines a standard API for loading and rendering templates regardless
  18. of the backend. Loading consists of finding the template for a given identifier
  19. and preprocessing it, usually compiling it to an in-memory representation.
  20. Rendering means interpolating the template with context data and returning the
  21. resulting string.
  22. The :doc:`Django template language </ref/templates/language>` is Django's own
  23. template system. Until Django 1.8 it was the only built-in option available.
  24. It's a good template library even though it's fairly opinionated and sports a
  25. few idiosyncrasies. If you don't have a pressing reason to choose another
  26. backend, you should use the DTL, especially if you're writing a pluggable
  27. application and you intend to distribute templates. Django's contrib apps that
  28. include templates, like :doc:`django.contrib.admin </ref/contrib/admin/index>`,
  29. use the DTL.
  30. For historical reasons, both the generic support for template engines and the
  31. implementation of the Django template language live in the ``django.template``
  32. namespace.
  33. .. warning::
  34. The template system isn't safe against untrusted template authors. For
  35. example, a site shouldn't allow its users to provide their own templates,
  36. since template authors can do things like perform XSS attacks and access
  37. properties of template variables that may contain sensitive information.
  38. .. _template-language-intro:
  39. The Django template language
  40. ============================
  41. .. highlight:: html+django
  42. Syntax
  43. ------
  44. .. admonition:: About this section
  45. This is an overview of the Django template language's syntax. For details
  46. see the :doc:`language syntax reference </ref/templates/language>`.
  47. A Django template is a text document or a Python string marked-up using the
  48. Django template language. Some constructs are recognized and interpreted by the
  49. template engine. The main ones are variables and tags.
  50. A template is rendered with a context. Rendering replaces variables with their
  51. values, which are looked up in the context, and executes tags. Everything else
  52. is output as is.
  53. The syntax of the Django template language involves four constructs.
  54. Variables
  55. ~~~~~~~~~
  56. A variable outputs a value from the context, which is a dict-like object
  57. mapping keys to values.
  58. Variables are surrounded by ``{{`` and ``}}`` like this::
  59. My first name is {{ first_name }}. My last name is {{ last_name }}.
  60. With a context of ``{'first_name': 'John', 'last_name': 'Doe'}``, this template
  61. renders to::
  62. My first name is John. My last name is Doe.
  63. Dictionary lookup, attribute lookup and list-index lookups are implemented with
  64. a dot notation::
  65. {{ my_dict.key }}
  66. {{ my_object.attribute }}
  67. {{ my_list.0 }}
  68. If a variable resolves to a callable, the template system will call it with no
  69. arguments and use its result instead of the callable.
  70. Tags
  71. ~~~~
  72. Tags provide arbitrary logic in the rendering process.
  73. This definition is deliberately vague. For example, a tag can output content,
  74. serve as a control structure e.g. an "if" statement or a "for" loop, grab
  75. content from a database, or even enable access to other template tags.
  76. Tags are surrounded by ``{%`` and ``%}`` like this::
  77. {% csrf_token %}
  78. Most tags accept arguments::
  79. {% cycle 'odd' 'even' %}
  80. Some tags require beginning and ending tags::
  81. {% if user.is_authenticated %}Hello, {{ user.username }}.{% endif %}
  82. A :ref:`reference of built-in tags <ref-templates-builtins-tags>` is
  83. available as well as :ref:`instructions for writing custom tags
  84. <howto-writing-custom-template-tags>`.
  85. Filters
  86. ~~~~~~~
  87. Filters transform the values of variables and tag arguments.
  88. They look like this::
  89. {{ django|title }}
  90. With a context of ``{'django': 'the web framework for perfectionists with
  91. deadlines'}``, this template renders to::
  92. The Web Framework For Perfectionists With Deadlines
  93. Some filters take an argument::
  94. {{ my_date|date:"Y-m-d" }}
  95. A :ref:`reference of built-in filters <ref-templates-builtins-filters>` is
  96. available as well as :ref:`instructions for writing custom filters
  97. <howto-writing-custom-template-filters>`.
  98. Comments
  99. ~~~~~~~~
  100. Comments look like this::
  101. {# this won't be rendered #}
  102. A :ttag:`{% comment %} <comment>` tag provides multi-line comments.
  103. Components
  104. ----------
  105. .. admonition:: About this section
  106. This is an overview of the Django template language's APIs. For details
  107. see the :doc:`API reference </ref/templates/api>`.
  108. Engine
  109. ~~~~~~
  110. :class:`django.template.Engine` encapsulates an instance of the Django
  111. template system. The main reason for instantiating an
  112. :class:`~django.template.Engine` directly is to use the Django template
  113. language outside of a Django project.
  114. :class:`django.template.backends.django.DjangoTemplates` is a thin wrapper
  115. adapting :class:`django.template.Engine` to Django's template backend API.
  116. Template
  117. ~~~~~~~~
  118. :class:`django.template.Template` represents a compiled template. Templates are
  119. obtained with :meth:`.Engine.get_template` or :meth:`.Engine.from_string`.
  120. Likewise ``django.template.backends.django.Template`` is a thin wrapper
  121. adapting :class:`django.template.Template` to the common template API.
  122. Context
  123. ~~~~~~~
  124. :class:`django.template.Context` holds some metadata in addition to the context
  125. data. It is passed to :meth:`.Template.render` for rendering a template.
  126. :class:`django.template.RequestContext` is a subclass of
  127. :class:`~django.template.Context` that stores the current
  128. :class:`~django.http.HttpRequest` and runs template context processors.
  129. The common API doesn't have an equivalent concept. Context data is passed in a
  130. plain :class:`dict` and the current :class:`~django.http.HttpRequest` is passed
  131. separately if needed.
  132. Loaders
  133. ~~~~~~~
  134. Template loaders are responsible for locating templates, loading them, and
  135. returning :class:`~django.template.Template` objects.
  136. Django provides several :ref:`built-in template loaders <template-loaders>`
  137. and supports :ref:`custom template loaders <custom-template-loaders>`.
  138. Context processors
  139. ~~~~~~~~~~~~~~~~~~
  140. Context processors are functions that receive the current
  141. :class:`~django.http.HttpRequest` as an argument and return a :class:`dict` of
  142. data to be added to the rendering context.
  143. Their main use is to add common data shared by all templates to the context
  144. without repeating code in every view.
  145. Django provides many :ref:`built-in context processors <context-processors>`,
  146. and you can implement your own additional context processors, too.
  147. .. _template-engines:
  148. Support for template engines
  149. ============================
  150. .. highlight:: python
  151. Configuration
  152. -------------
  153. Templates engines are configured with the :setting:`TEMPLATES` setting. It's a
  154. list of configurations, one for each engine. The default value is empty. The
  155. ``settings.py`` generated by the :djadmin:`startproject` command defines a
  156. more useful value::
  157. TEMPLATES = [
  158. {
  159. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  160. 'DIRS': [],
  161. 'APP_DIRS': True,
  162. 'OPTIONS': {
  163. # ... some options here ...
  164. },
  165. },
  166. ]
  167. :setting:`BACKEND <TEMPLATES-BACKEND>` is a dotted Python path to a template
  168. engine class implementing Django's template backend API. The built-in backends
  169. are :class:`django.template.backends.django.DjangoTemplates` and
  170. :class:`django.template.backends.jinja2.Jinja2`.
  171. Since most engines load templates from files, the top-level configuration for
  172. each engine contains two common settings:
  173. * :setting:`DIRS <TEMPLATES-DIRS>` defines a list of directories where the
  174. engine should look for template source files, in search order.
  175. * :setting:`APP_DIRS <TEMPLATES-APP_DIRS>` tells whether the engine should
  176. look for templates inside installed applications. Each backend defines a
  177. conventional name for the subdirectory inside applications where its
  178. templates should be stored.
  179. While uncommon, it's possible to configure several instances of the same
  180. backend with different options. In that case you should define a unique
  181. :setting:`NAME <TEMPLATES-NAME>` for each engine.
  182. :setting:`OPTIONS <TEMPLATES-OPTIONS>` contains backend-specific settings.
  183. Usage
  184. -----
  185. .. _template-loading:
  186. .. module:: django.template.loader
  187. The ``django.template.loader`` module defines two functions to load templates.
  188. .. function:: get_template(template_name, using=None)
  189. This function loads the template with the given name and returns a
  190. ``Template`` object.
  191. The exact type of the return value depends on the backend that loaded the
  192. template. Each backend has its own ``Template`` class.
  193. ``get_template()`` tries each template engine in order until one succeeds.
  194. If the template cannot be found, it raises
  195. :exc:`~django.template.TemplateDoesNotExist`. If the template is found but
  196. contains invalid syntax, it raises
  197. :exc:`~django.template.TemplateSyntaxError`.
  198. How templates are searched and loaded depends on each engine's backend and
  199. configuration.
  200. If you want to restrict the search to a particular template engine, pass
  201. the engine's :setting:`NAME <TEMPLATES-NAME>` in the ``using`` argument.
  202. .. function:: select_template(template_name_list, using=None)
  203. ``select_template()`` is just like ``get_template()``, except it takes a
  204. list of template names. It tries each name in order and returns the first
  205. template that exists.
  206. .. currentmodule:: django.template
  207. If loading a template fails, the following two exceptions, defined in
  208. ``django.template``, may be raised:
  209. .. exception:: TemplateDoesNotExist(msg, tried=None, backend=None, chain=None)
  210. This exception is raised when a template cannot be found. It accepts the
  211. following optional arguments for populating the :ref:`template postmortem
  212. <template-postmortem>` on the debug page:
  213. ``backend``
  214. The template backend instance from which the exception originated.
  215. ``tried``
  216. A list of sources that were tried when finding the template. This is
  217. formatted as a list of tuples containing ``(origin, status)``, where
  218. ``origin`` is an :ref:`origin-like <template-origin-api>` object and
  219. ``status`` is a string with the reason the template wasn't found.
  220. ``chain``
  221. A list of intermediate :exc:`~django.template.TemplateDoesNotExist`
  222. exceptions raised when trying to load a template. This is used by
  223. functions, such as :func:`~django.template.loader.get_template`, that
  224. try to load a given template from multiple engines.
  225. .. exception:: TemplateSyntaxError(msg)
  226. This exception is raised when a template was found but contains errors.
  227. ``Template`` objects returned by ``get_template()`` and ``select_template()``
  228. must provide a ``render()`` method with the following signature:
  229. .. currentmodule:: django.template.backends.base
  230. .. method:: Template.render(context=None, request=None)
  231. Renders this template with a given context.
  232. If ``context`` is provided, it must be a :class:`dict`. If it isn't
  233. provided, the engine will render the template with an empty context.
  234. If ``request`` is provided, it must be an :class:`~django.http.HttpRequest`.
  235. Then the engine must make it, as well as the CSRF token, available in the
  236. template. How this is achieved is up to each backend.
  237. Here's an example of the search algorithm. For this example the
  238. :setting:`TEMPLATES` setting is::
  239. TEMPLATES = [
  240. {
  241. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  242. 'DIRS': [
  243. '/home/html/example.com',
  244. '/home/html/default',
  245. ],
  246. },
  247. {
  248. 'BACKEND': 'django.template.backends.jinja2.Jinja2',
  249. 'DIRS': [
  250. '/home/html/jinja2',
  251. ],
  252. },
  253. ]
  254. If you call ``get_template('story_detail.html')``, here are the files Django
  255. will look for, in order:
  256. * ``/home/html/example.com/story_detail.html`` (``'django'`` engine)
  257. * ``/home/html/default/story_detail.html`` (``'django'`` engine)
  258. * ``/home/html/jinja2/story_detail.html`` (``'jinja2'`` engine)
  259. If you call ``select_template(['story_253_detail.html', 'story_detail.html'])``,
  260. here's what Django will look for:
  261. * ``/home/html/example.com/story_253_detail.html`` (``'django'`` engine)
  262. * ``/home/html/default/story_253_detail.html`` (``'django'`` engine)
  263. * ``/home/html/jinja2/story_253_detail.html`` (``'jinja2'`` engine)
  264. * ``/home/html/example.com/story_detail.html`` (``'django'`` engine)
  265. * ``/home/html/default/story_detail.html`` (``'django'`` engine)
  266. * ``/home/html/jinja2/story_detail.html`` (``'jinja2'`` engine)
  267. When Django finds a template that exists, it stops looking.
  268. .. admonition:: Tip
  269. You can use :func:`~django.template.loader.select_template()` for flexible
  270. template loading. For example, if you've written a news story and want
  271. some stories to have custom templates, use something like
  272. ``select_template(['story_%s_detail.html' % story.id,
  273. 'story_detail.html'])``. That'll allow you to use a custom template for an
  274. individual story, with a fallback template for stories that don't have
  275. custom templates.
  276. It's possible -- and preferable -- to organize templates in subdirectories
  277. inside each directory containing templates. The convention is to make a
  278. subdirectory for each Django app, with subdirectories within those
  279. subdirectories as needed.
  280. Do this for your own sanity. Storing all templates in the root level of a
  281. single directory gets messy.
  282. To load a template that's within a subdirectory, use a slash, like so::
  283. get_template('news/story_detail.html')
  284. Using the same :setting:`TEMPLATES` option as above, this will attempt to load
  285. the following templates:
  286. * ``/home/html/example.com/news/story_detail.html`` (``'django'`` engine)
  287. * ``/home/html/default/news/story_detail.html`` (``'django'`` engine)
  288. * ``/home/html/jinja2/news/story_detail.html`` (``'jinja2'`` engine)
  289. .. currentmodule:: django.template.loader
  290. In addition, to cut down on the repetitive nature of loading and rendering
  291. templates, Django provides a shortcut function which automates the process.
  292. .. function:: render_to_string(template_name, context=None, request=None, using=None)
  293. ``render_to_string()`` loads a template like :func:`get_template` and
  294. calls its ``render()`` method immediately. It takes the following
  295. arguments.
  296. ``template_name``
  297. The name of the template to load and render. If it's a list of template
  298. names, Django uses :func:`select_template` instead of
  299. :func:`get_template` to find the template.
  300. ``context``
  301. A :class:`dict` to be used as the template's context for rendering.
  302. ``request``
  303. An optional :class:`~django.http.HttpRequest` that will be available
  304. during the template's rendering process.
  305. ``using``
  306. An optional template engine :setting:`NAME <TEMPLATES-NAME>`. The
  307. search for the template will be restricted to that engine.
  308. Usage example::
  309. from django.template.loader import render_to_string
  310. rendered = render_to_string('my_template.html', {'foo': 'bar'})
  311. See also the :func:`~django.shortcuts.render()` shortcut which calls
  312. :func:`render_to_string()` and feeds the result into an
  313. :class:`~django.http.HttpResponse` suitable for returning from a view.
  314. Finally, you can use configured engines directly:
  315. .. data:: engines
  316. Template engines are available in ``django.template.engines``::
  317. from django.template import engines
  318. django_engine = engines['django']
  319. template = django_engine.from_string("Hello {{ name }}!")
  320. The lookup key — ``'django'`` in this example — is the engine's
  321. :setting:`NAME <TEMPLATES-NAME>`.
  322. .. module:: django.template.backends
  323. Built-in backends
  324. -----------------
  325. .. module:: django.template.backends.django
  326. .. class:: DjangoTemplates
  327. Set :setting:`BACKEND <TEMPLATES-BACKEND>` to
  328. ``'django.template.backends.django.DjangoTemplates'`` to configure a Django
  329. template engine.
  330. When :setting:`APP_DIRS <TEMPLATES-APP_DIRS>` is ``True``, ``DjangoTemplates``
  331. engines look for templates in the ``templates`` subdirectory of installed
  332. applications. This generic name was kept for backwards-compatibility.
  333. ``DjangoTemplates`` engines accept the following :setting:`OPTIONS
  334. <TEMPLATES-OPTIONS>`:
  335. * ``'autoescape'``: a boolean that controls whether HTML autoescaping is
  336. enabled.
  337. It defaults to ``True``.
  338. .. warning::
  339. Only set it to ``False`` if you're rendering non-HTML templates!
  340. * ``'context_processors'``: a list of dotted Python paths to callables that
  341. are used to populate the context when a template is rendered with a request.
  342. These callables take a request object as their argument and return a
  343. :class:`dict` of items to be merged into the context.
  344. It defaults to an empty list.
  345. See :class:`~django.template.RequestContext` for more information.
  346. * ``'debug'``: a boolean that turns on/off template debug mode. If it is
  347. ``True``, the fancy error page will display a detailed report for any
  348. exception raised during template rendering. This report contains the
  349. relevant snippet of the template with the appropriate line highlighted.
  350. It defaults to the value of the :setting:`DEBUG` setting.
  351. * ``'loaders'``: a list of dotted Python paths to template loader classes.
  352. Each ``Loader`` class knows how to import templates from a particular
  353. source. Optionally, a tuple can be used instead of a string. The first item
  354. in the tuple should be the ``Loader`` class name, and subsequent items are
  355. passed to the ``Loader`` during initialization.
  356. The default depends on the values of :setting:`DIRS <TEMPLATES-DIRS>` and
  357. :setting:`APP_DIRS <TEMPLATES-APP_DIRS>`.
  358. See :ref:`template-loaders` for details.
  359. * ``'string_if_invalid'``: the output, as a string, that the template system
  360. should use for invalid (e.g. misspelled) variables.
  361. It defaults to an empty string.
  362. See :ref:`invalid-template-variables` for details.
  363. * ``'file_charset'``: the charset used to read template files on disk.
  364. It defaults to ``'utf-8'``.
  365. * ``'libraries'``: A dictionary of labels and dotted Python paths of template
  366. tag modules to register with the template engine. This can be used to add
  367. new libraries or provide alternate labels for existing ones. For example::
  368. OPTIONS={
  369. 'libraries': {
  370. 'myapp_tags': 'path.to.myapp.tags',
  371. 'admin.urls': 'django.contrib.admin.templatetags.admin_urls',
  372. },
  373. }
  374. Libraries can be loaded by passing the corresponding dictionary key to
  375. the :ttag:`{% load %}<load>` tag.
  376. * ``'builtins'``: A list of dotted Python paths of template tag modules to
  377. add to :doc:`built-ins </ref/templates/builtins>`. For example::
  378. OPTIONS={
  379. 'builtins': ['myapp.builtins'],
  380. }
  381. Tags and filters from built-in libraries can be used without first calling
  382. the :ttag:`{% load %} <load>` tag.
  383. .. module:: django.template.backends.jinja2
  384. .. class:: Jinja2
  385. Requires Jinja2_ to be installed:
  386. .. console::
  387. $ python -m pip install Jinja2
  388. Set :setting:`BACKEND <TEMPLATES-BACKEND>` to
  389. ``'django.template.backends.jinja2.Jinja2'`` to configure a Jinja2_ engine.
  390. When :setting:`APP_DIRS <TEMPLATES-APP_DIRS>` is ``True``, ``Jinja2`` engines
  391. look for templates in the ``jinja2`` subdirectory of installed applications.
  392. The most important entry in :setting:`OPTIONS <TEMPLATES-OPTIONS>` is
  393. ``'environment'``. It's a dotted Python path to a callable returning a Jinja2
  394. environment. It defaults to ``'jinja2.Environment'``. Django invokes that
  395. callable and passes other options as keyword arguments. Furthermore, Django
  396. adds defaults that differ from Jinja2's for a few options:
  397. * ``'autoescape'``: ``True``
  398. * ``'loader'``: a loader configured for :setting:`DIRS <TEMPLATES-DIRS>` and
  399. :setting:`APP_DIRS <TEMPLATES-APP_DIRS>`
  400. * ``'auto_reload'``: ``settings.DEBUG``
  401. * ``'undefined'``: ``DebugUndefined if settings.DEBUG else Undefined``
  402. ``Jinja2`` engines also accept the following :setting:`OPTIONS
  403. <TEMPLATES-OPTIONS>`:
  404. * ``'context_processors'``: a list of dotted Python paths to callables that
  405. are used to populate the context when a template is rendered with a request.
  406. These callables take a request object as their argument and return a
  407. :class:`dict` of items to be merged into the context.
  408. It defaults to an empty list.
  409. .. admonition:: Using context processors with Jinja2 templates is discouraged.
  410. Context processors are useful with Django templates because Django templates
  411. don't support calling functions with arguments. Since Jinja2 doesn't have
  412. that limitation, it's recommended to put the function that you would use as a
  413. context processor in the global variables available to the template using
  414. ``jinja2.Environment`` as described below. You can then call that function in
  415. the template:
  416. .. code-block:: jinja
  417. {{ function(request) }}
  418. Some Django templates context processors return a fixed value. For Jinja2
  419. templates, this layer of indirection isn't necessary since you can add
  420. constants directly in ``jinja2.Environment``.
  421. The original use case for adding context processors for Jinja2 involved:
  422. * Making an expensive computation that depends on the request.
  423. * Needing the result in every template.
  424. * Using the result multiple times in each template.
  425. Unless all of these conditions are met, passing a function to the template is
  426. more in line with the design of Jinja2.
  427. The default configuration is purposefully kept to a minimum. If a template is
  428. rendered with a request (e.g. when using :py:func:`~django.shortcuts.render`),
  429. the ``Jinja2`` backend adds the globals ``request``, ``csrf_input``, and
  430. ``csrf_token`` to the context. Apart from that, this backend doesn't create a
  431. Django-flavored environment. It doesn't know about Django filters and tags.
  432. In order to use Django-specific APIs, you must configure them into the
  433. environment.
  434. For example, you can create ``myproject/jinja2.py`` with this content::
  435. from django.templatetags.static import static
  436. from django.urls import reverse
  437. from jinja2 import Environment
  438. def environment(**options):
  439. env = Environment(**options)
  440. env.globals.update({
  441. 'static': static,
  442. 'url': reverse,
  443. })
  444. return env
  445. and set the ``'environment'`` option to ``'myproject.jinja2.environment'``.
  446. Then you could use the following constructs in Jinja2 templates:
  447. .. code-block:: html+jinja
  448. <img src="{{ static('path/to/company-logo.png') }}" alt="Company Logo">
  449. <a href="{{ url('admin:index') }}">Administration</a>
  450. The concepts of tags and filters exist both in the Django template language
  451. and in Jinja2 but they're used differently. Since Jinja2 supports passing
  452. arguments to callables in templates, many features that require a template tag
  453. or filter in Django templates can be achieved by calling a function in Jinja2
  454. templates, as shown in the example above. Jinja2's global namespace removes the
  455. need for template context processors. The Django template language doesn't have
  456. an equivalent of Jinja2 tests.
  457. .. _Jinja2: https://jinja.palletsprojects.com/