templates.txt 24 KB

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