Context Processor for Global Template Data
A snippet to add a custom context processor and register it.
# app/context_processors.py
def global_settings(request):
return {'SITE_NAME': 'Acme Inc', 'SUPPORT_EMAIL': '[email protected]'}
# settings.py
TEMPLATES = [
{
# ...,
'OPTIONS': {
'context_processors': [
# existing context processors...
'app.context_processors.global_settings',
],
},
},
]
# templates/base.html
<footer>Contact: {{ SUPPORT_EMAIL }}</footer>
Explanation:
- Return a dict from the context processor; keys become template variables.
-
Register it in
TEMPLATES[0]['OPTIONS']['context_processors'].
- Category Utilities & Miscellaneous
- Total Views 988
- Last Modified 14 July, 2026
- Tags #context #templates #utilities #settings
Previous snippet
Background Tasks with Celery
Next snippet