diff options
| author | Adam Johnson <me@adamj.eu> | 2021-02-11 13:36:32 +0000 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2021-02-11 14:37:27 +0100 |
| commit | f2d955dbe4b24da5ac21c71caf3ca459db1fcd04 (patch) | |
| tree | d08d55d298d45f817732a935ec48538cd36d47f6 /docs/ref | |
| parent | 2ce4f7324193e3110af83a53e9d2f744b6d9166c (diff) | |
[3.2.x] Documented an example custom context processor.
Backport of 0963f184abd96800b76b19a6a181e1b544c7fafe from master
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/templates/api.txt | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt index f9647fd83a..01748715b7 100644 --- a/docs/ref/templates/api.txt +++ b/docs/ref/templates/api.txt @@ -755,8 +755,17 @@ Writing your own context processors A context processor has a simple interface: It's a Python function that takes one argument, an :class:`~django.http.HttpRequest` object, and returns a -dictionary that gets added to the template context. Each context processor -*must* return a dictionary. +dictionary that gets added to the template context. + +For example, to add the :setting:`DEFAULT_FROM_EMAIL` setting to every +context:: + + from django.conf import settings + + def from_email(request): + return { + "DEFAULT_FROM_EMAIL": settings.DEFAULT_FROM_EMAIL, + } Custom context processors can live anywhere in your code base. All Django cares about is that your custom context processors are pointed to by the |
