Python 检查Jinja2中变量的类型

Python 检查Jinja2中变量的类型,python,jinja2,Python,Jinja2,我想检查Jinja2中变量的类型。如果它是变量类型是dictionary,那么我必须在段落中打印一些文本,如果它不是dict,那么我必须打印一些其他值 我在这里尝试的是 {% if {{result}} is dict %} <tr> <td> <p> The details are not here </p> </td> </tr> {% else %} {% for each_value in result %} <

我想检查Jinja2中变量的类型。如果它是变量类型是dictionary,那么我必须在段落中打印一些文本,如果它不是dict,那么我必须打印一些其他值

我在这里尝试的是

{% if {{result}} is dict %}
<tr>
<td>
<p> The details are not here </p>
</td>
</tr>
{% else %}
{% for each_value in result %}
<tr>
<td>each_value.student_name</td>
</tr>
{% endfor %}
{% endif %}
结果的另一种格式是

II.result=[{'student_name':'b','student_id':2,'student_email':'my_nameb@gmail.com','time':[{'st':1,'et':2},{'st':3,'et':4}]}]

您应该将
{%if{result}}是dict%}
替换为
{%if result是mapping%}

II.result=[{'student_name':'b','student_id':2,'student_email':'my_nameb@gmail.com','time':[{'st':1,'et':2},{'st':3,'et':4}]}]
Expected result
If I get the format 'I' then the if loop should get execute.
If I get the format 'II' then the else loop should get execute.
Actual result
jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'