1
0
mirror of https://github.com/django/django.git synced 2025-06-05 03:29:12 +00:00

[3.2.x] Documented an example custom context processor.

Backport of 0963f184abd96800b76b19a6a181e1b544c7fafe from master
This commit is contained in:
Adam Johnson 2021-02-11 13:36:32 +00:00 committed by Carlton Gibson
parent 2ce4f73241
commit f2d955dbe4

View File

@ -755,8 +755,17 @@ Writing your own context processors
A context processor has a simple interface: It's a Python function that takes 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 one argument, an :class:`~django.http.HttpRequest` object, and returns a
dictionary that gets added to the template context. Each context processor dictionary that gets added to the template context.
*must* return a dictionary.
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 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 cares about is that your custom context processors are pointed to by the