0 day streak
python / beginner
Snippet

Using Context Processors for Global Data

Context processors are functions that return a dictionary to be added to the template context for every single request.

snippet.py
python
1
2
3
4
5
def site_settings(request):
return {
'site_name': 'My Code Portal',
'is_maintenance': False
}
django
Breakdown
1
def site_settings(request):
The function must accept a request object as its only argument.
2
return { ... }
Returns a dictionary of variables that will be globally available in all templates.