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?
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.
Django provides access to certain, frequently-used settings constants to the template such as
settings.MEDIA_URLand some of the language settings if you use django’s built in generic views or pass in a context instance keyword argument in therender_to_responseshortcut function. Here’s an example of each case:These views will both have several frequently used settings like
settings.MEDIA_URLavailable to the template as{{ MEDIA_URL }}, etc.If you’re looking for access to other constants in the settings, then simply unpack the constants you want and add them to the context dictionary you’re using in your view function, like so:
Now you can access
settings.FAVORITE_COLORon your template as{{ favorite_color }}.