【发布时间】:2015-01-02 09:45:48
【问题描述】:
我有一本 python 字典:
settings = {
"foo" : "baz",
"hello" : "world"
}
这个变量 settings 然后在 Jinja2 模板中可用。
我想检查我的模板中的 settings 字典中是否存在键 myProperty,如果存在,请采取一些措施:
{% if settings.hasKey(myProperty) %}
takeSomeAction();
{% endif %}
我可以使用的 hasKey 等价物是什么?
【问题讨论】:
-
检查一下:如果 settings[myproperty] 不是 None:我认为这应该可行。
-
或者如果 settings.myproperty 被定义: