如何检查变量是否是 jinja 中的字典

SIU*_*IUV 5 python jinja2

set x = {'a':1}

如何查明 x 是否是 jinja 中的字典?我试图说是否可迭代,但无法区分列表、字符串或字典。我想知道变量是否是字典。

小智 5

使用映射过滤器,例如

{% if x is mapping %} 
do something 
{% endif %}
Run Code Online (Sandbox Code Playgroud)