Django: exposing settings in templates, the easy way

NOTE: I have submitted a patch to have this functionality as part of Django core. I’m posting this code here in case the patch gets rejected, since similar motions have previously been rejected. The ticket is at, and I will update this post if the patch gets accepted.

I find it very handy to be able to expose parts of in templates. The Django docs show you how to do this using context processors and give the code for the MEDIA_URL context processor here. However, it seems silly to me to have to write custom processors all the time. Instead, I propose a single processor that exposes a list of settings (stored in itself) to the template layer.

The gist containing the code is here:


Tags: , ,

2 Responses to “Django: exposing settings in templates, the easy way”

  1. Mike Malone says:

    Another approach is to use the get_safe_settings function from django.views.debug. If you use that function, make sure you look at it’s implementation since it just filters for certain words that make a setting “dangerous” (like “password”). Here’s my context processor for getting settings into templates:

    The code for get_safe_settings is here:

  2. Thanks for this post. I am new at development and this is a big help.

Leave a Reply