我有我像这样传递给模板的字典
dict['vars'] = ['a':'dd','b':'gg','c':'yy']
dict['myvars'] = ['a':'tt','b':'yy','c':'uu']
有时
当单个字典为空且没有键时。
我怎么能像这样检查
{% if dict.vars empty %}
do this
{% if not dict.vars %}
do this
{% endif %}
这:
{% if dict|length > 0 %}
do this
{% endif %}
也应该做得很好。
你也可以这样做:
{% if not "vars" in dict %}
Hello
{% else %}
abc
{% endif %}
您也可以像这样检查字典是否为空
{% if not 'bool(video_url_dict)' %}
{% if 'bool(video_url_dict)' %}
这将正常工作。