Binary Lion Studios

I code for fun and for food.

Access settings in template with setting tag

A simple Django template tag to access settings from a template.

appname/templatetags/setting.py
1
2
3
4
5
6
7
8
from django import template
from django.conf import settings

register = template.Library()

@register.simple_tag
def setting(value):
    return getattr(settings, value, '')

And you can use it in a template like this:

1
2
3
{% load setting %}

The current timezone is set to {% setting 'TIME_ZONE' %}.

Note: Make sure you have the __init__.py file in your appname/templatetags directory. Also, if you had to add it, you will need to restart the server for the tag to be available.