Django settings in templateComputing · django
So what do you do if you require a django setting in your templates, much like we have MEDIA_URL today?
Well there are use cases for this, (if you are in doubt have a look at the original ticket for adding MEDIA_URL to django ).
Now from here I would like to make this available in my templates. Create a new python file that is somewhere on your python path (Under my project, I create a utils directory and then put a file context_processors.py in there. Don’t forget \__init__.py should live in that directory as well).
In the context_processors.py file simply put
from django.conf import settings<br />
In your settings.py file you might already have a reference to TEMPLATE_CONTEXT_PROCESSORS if not then add it like so:
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS<br />
TEMPLATE_CONTEXT_PROCESSORS += (<br />
comments powered by Disqus