Skip to content

Instantly share code, notes, and snippets.

@akobashikawa
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akobashikawa/e29caee5e31bdbfa712c to your computer and use it in GitHub Desktop.
Save akobashikawa/e29caee5e31bdbfa712c to your computer and use it in GitHub Desktop.
Django tag to publish some settings value in template
# based upon ideas in http://stackoverflow.com/a/6343321
@register.simple_tag(takes_context=True)
def settings_value(context, name):
PUBLIC_SETTINGS_NAMES = ("THEME_DEBUG",)
if name in PUBLIC_SETTINGS_NAMES:
context[name] = getattr(settings, name, "")
return ''
return ''
@akobashikawa
Copy link
Author

With PUBLIC_SETTINGS_NAMES in settings:

@register.simple_tag(takes_context=True)
def settings_value(context, name):
    PUBLIC_SETTINGS_NAMES = settings.PUBLIC_SETTINGS_NAMES
    if name in PUBLIC_SETTINGS_NAMES:
        context[name] = getattr(settings, name, "")
        return ''
    return ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment