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?
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?
Check out
django-settings-export
(disclaimer: I'm the author of this project).For example...
settings.py
template.html
I improved chrisdew's answer (to create your own tag) a little bit.
First, create the file
yourapp/templatetags/value_from_settings.py
in which you define your own new tagvalue_from_settings
:You can use this tag in your Template via:
or via
The advantage of the
as ...
notation is that this makes it easy to use inblocktrans
blocks via a simple{{my_fqdn}}
.I found this to be the simplest approach for Django 1.3:
views.py
hero.html