diff options
| author | Berker Peksag <berker.peksag@gmail.com> | 2016-06-27 16:56:21 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-28 14:30:54 -0400 |
| commit | 52a991d9766de08b411ee05e2166ed9576da3458 (patch) | |
| tree | 71434dfc527725b5784b04b198cc79a5e12f31af /docs | |
| parent | 222e1334bf29605925eefa45ff107ca1155e93c0 (diff) | |
Fixed #24694 -- Added support for context_processors to Jinja2 backend.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/1.11.txt | 4 | ||||
| -rw-r--r-- | docs/topics/templates.txt | 20 |
2 files changed, 21 insertions, 3 deletions
diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt index 974e1e4adb..5bac7e0b0a 100644 --- a/docs/releases/1.11.txt +++ b/docs/releases/1.11.txt @@ -220,6 +220,10 @@ Templates * :meth:`~django.utils.safestring.mark_safe` can now be used as a decorator. +* The :class:`~django.template.backends.jinja2.Jinja2` template backend now + supports context processors by setting the ``'context_processors'`` option in + :setting:`OPTIONS <TEMPLATES-OPTIONS>`. + Tests ~~~~~ diff --git a/docs/topics/templates.txt b/docs/topics/templates.txt index 8f21f936ab..2fa9bcfeac 100644 --- a/docs/topics/templates.txt +++ b/docs/topics/templates.txt @@ -398,13 +398,27 @@ adds defaults that differ from Jinja2's for a few options: * ``'auto_reload'``: ``settings.DEBUG`` * ``'undefined'``: ``DebugUndefined if settings.DEBUG else Undefined`` +``Jinja2`` engines also accept the following :setting:`OPTIONS +<TEMPLATES-OPTIONS>`: + +* ``'context_processors'``: a list of dotted Python paths to callables that + are used to populate the context when a template is rendered with a request. + These callables take a request object as their argument and return a + :class:`dict` of items to be merged into the context. + + It defaults to an empty list. + +.. versionadded:: 1.11 + + The ``'context_processors'`` option was added. + The default configuration is purposefully kept to a minimum. If a template is rendered with a request (e.g. when using :py:func:`~django.shortcuts.render`), the ``Jinja2`` backend adds the globals ``request``, ``csrf_input``, and ``csrf_token`` to the context. Apart from that, this backend doesn't create a -Django-flavored environment. It doesn't know about Django context processors, -filters, and tags. In order to use Django-specific APIs, you must configure -them into the environment. +Django-flavored environment. It doesn't know about Django filters and tags. +In order to use Django-specific APIs, you must configure them into the +environment. For example, you can create ``myproject/jinja2.py`` with this content:: |
