Sometimes you need a variable in your templates thats required for every page in your site.
Inserting it into every return statement in every view is a bit too troublesome.
Its much easier to add it into a "Context Processor". This will automatically insert the data you specify into every template rendered.
So in your app, create a file called "context_processor.py" and define the processors you need.
1.
def
custom_info(request):
2.
return
{
'MY_CUSTOM_INFO'
:
'blah blah blah'
, }
Now in your settings, include the preprocessor.
1.
TEMPLATE_CONTEXT_PROCESSORS
=
(
2.
'django.core.context_processors.request'
,
3.
'myapp.context_processors.custom_info'
,
4.
)
In your template, use it like normal without needing to load anything.
1.
<
div
>Data: {{ MY_CUSTOM_INFO }}</
div
>