在设置中定义常量,并使其在模板中可用。
django-tagconstants的Python项目详细描述
django标记常量
在设置文件中定义常量,然后在 你的模板。
安装
从命令行:
pip install django-tagconstants
向已安装的应用程序添加标记常量:
INSTALLED_APPS=(...'tagconstants',...)
在settings.py文件中创建TAG_CONSTANTS字典:
TAG_CONSTANTS={}
用法
为了安全起见,tagconstants的设计使您可以创建 要在模板中提供的变量的白名单。更多 有关信息,请参阅设计和安全部分。
若要在模板中使用常量,请首先将该常量添加到 TAG_CONSTANTS设置:
TAG_CONSTANTS={'CONSTANT':'SOME STRING',}
然后在模板中,可以使用 {% constant ... %}模板标记:
{% load tagconstants %} {% constant "CONSTANT" %} {# renders to 'SOME STRING' #} {% constant "CONSTANT" as "variable_name" %} {# loads the template variable variable_name="SOME STRING" #} {# into the template context #}
贡献
拉,叉子,你想用密码做什么就做什么。