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'].
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.