1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | from django import template
from django.conf import settings
register = template.Library()
@register.tag
def setting ( parser, token ):
try:
tag_name, option = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents[0]
return SettingNode( option )
class SettingNode ( template.Node ):
def __init__ ( self, option ):
self.option = option
def render ( self, context ):
# if FAILURE then FAIL silently
try:
return str(settings.__getattr__(self.option))
except:
return ""
|
Comments
"be generic" (c)
#
In fact, I want settings so often that I put that into context:
settings.py
context_processors.py
#
from django.conf import settings register = template.Library()
#