Documented an example custom context processor.

This commit is contained in:
Adam Johnson 2021-02-11 13:36:32 +00:00 committed by GitHub
parent a57e91adee
commit 0963f184ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

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
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