I have some stuff in settings.py that I'd like to be able to access from a template, but I can't figure out how to do it. I already tried
{{CONSTANT_NAME}}
but that doesn't seem to work. Is this possible?
djangodjango-settingsdjango-templates
I have some stuff in settings.py that I'd like to be able to access from a template, but I can't figure out how to do it. I already tried
{{CONSTANT_NAME}}
but that doesn't seem to work. Is this possible?
Best Answer
If it's a value you'd like to have for every request & template, using a context processor is more appropriate.
Here's how:
Make a
context_processors.py
file in your app directory. Let's say I want to have theADMIN_PREFIX_VALUE
value in every context:add your context processor to your settings.py file:
Use
RequestContext
in your view to add your context processors in your template. Therender
shortcut does this automatically:and finally, in your template: