summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Higgins <johnmatthiggins@gmail.com>2024-05-13 08:15:53 -0700
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-06-20 09:37:34 +0200
commit874fea63b477851d5902200ab3f7ed139c1c9cd2 (patch)
tree55250052a330f429112e9fdedb6d992715ddf5f2
parent8eb84abf229c1ca4cd044d17cd15b3def8e78d13 (diff)
[5.1.x] Fixed #35441 -- Documented Context and RequestContext keyword arguments.
Backport of 60acad933d66e116c89150d3eb9040f62ca871a1 from main.
-rw-r--r--docs/ref/templates/api.txt33
1 files changed, 29 insertions, 4 deletions
diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt
index 26e4ff4c23..a46717b8d7 100644
--- a/docs/ref/templates/api.txt
+++ b/docs/ref/templates/api.txt
@@ -201,12 +201,37 @@ Once you have a compiled :class:`Template` object, you can render a context
with it. You can reuse the same template to render it several times with
different contexts.
-.. class:: Context(dict_=None)
+.. class:: Context(dict_=None, autoescape=True, use_l10n=None, use_tz=None)
The constructor of ``django.template.Context`` takes an optional argument —
a dictionary mapping variable names to variable values.
- For details, see :ref:`playing-with-context` below.
+ Three optional keyword arguments can also be specified:
+
+ * ``autoescape`` controls whether HTML autoescaping is enabled.
+
+ It defaults to ``True``.
+
+ .. warning::
+
+ Only set it to ``False`` if you're rendering non-HTML templates!
+
+ * ``use_l10n`` overrides whether values will be localized by default. If
+ set to ``True`` numbers and dates will be formatted based on locale.
+
+ It defaults to ``None``.
+
+ See :ref:`topic-l10n-templates` for details.
+
+ * ``use_tz`` overrides whether dates are converted to the local time when
+ rendered in a template. If set to ``True`` all dates will be rendered
+ using the local timezone. This takes precedence over :setting:`USE_TZ`.
+
+ It defaults to ``None``.
+
+ See :ref:`time-zones-in-templates` for details.
+
+ For example usage, see :ref:`playing-with-context` below.
.. method:: Template.render(context)
@@ -610,9 +635,9 @@ against ``dict``::
Using ``RequestContext``
------------------------
-.. class:: RequestContext(request, dict_=None, processors=None)
+.. class:: RequestContext(request, dict_=None, processors=None, use_l10n=None, use_tz=None, autoescape=True)
-Django comes with a special ``Context`` class,
+Django comes with a special :class:`~django.template.Context` class,
``django.template.RequestContext``, that acts slightly differently from the
normal ``django.template.Context``. The first difference is that it takes an
:class:`~django.http.HttpRequest` as its first argument. For example::