Context Processor (Django)
A context processor is a function that injects variables into every template's context automatically. Django uses them to make values like the current user available in all templates without passing them from each view.
Django
Sometimes the same data is needed in many templates — the logged-in user, the site name, a cart count. A context processor centralizes that: it is a function taking the request and returning a dict, and Django merges that dict into the context of every rendered template.
Django enables several by default (auth, which provides {{ user }} and {{ perms }}; messages; debug; and request via the request processor). You add your own by listing it in the TEMPLATES setting's context_processors option.
Use them sparingly — they run on every template render, so heavy queries inside one slow your whole site. They are best for small, broadly needed values.
Syntax
def my_processor(request):
return {"site_name": "Demo"}Examples
Python
# blog/context_processors.py
def site_info(request):
return {"site_name": "My Blog", "year": 2026}
# settings.py TEMPLATES -> OPTIONS -> context_processors:
# "blog.context_processors.site_info"
# Now {{ site_name }} works in any template.