Issue
I want to check the type of variable in Jinja2. If it is type of variable is dictionary then I have to print some text in the paragraph and if it's not dict then I have to print some other values.
What I tried here is
{% 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 %}
The result I get is two different ways one is of dict type
I.result={'student_name':'a','student_id':1,'student_email':'[email protected]'}
the another format of result is
II.result=[{'student_name':'b','student_id':2,'student_email':'[email protected]','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 '}'
Solution
You should replace {% if {{result}} is dict %}
with {% if result is mapping %}
.
Answered By - sashaaero
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.