I want to be able to put certain configuration information in my settings.py file – things like the site name, site url, etc.
If I do this, how can I then access those settings in templates?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s say in your
settings.pyfile you have:If you need that in just one or two views:
If you need to access these across a lot of apps and/or views, you can write a context processor to save code:
James has a tutorial on this
online.
Some useful information on the when and if of context processors is available on this very site
here.
Inside your
my_context_processors.pyfile you would:Back in your
settings.py, activate it by doing:In your
views.py, make a view use it like so: