Home How can I render object containing dictionaries to templates in jinja2?

# How can I render object containing dictionaries to templates in jinja2?

user7271
1#
user7271 Published in September 21, 2018, 8:09 am

suppose If lists are a1=[ ],a2=[ ],a3=[ ],a4=[ ],a5=[ ]

they all will have dynamic values as below:

a1=[]
a2=[]
a3=[{'car':'bez','city':'la','aero':'vaar'}]
a4=[]
a5=[{'car':'tez','city':'pa','aero':'vawear'}]


I want to render only those which has values as in this case a3 and a5 then how can I check lists which have values then render it to template card.html

<table>
<tbody>
<th>car</th>
<th>city</th>
<th>aero</th>
{{for key in a3 /a5}}
<td>key[car]</td>
<td>key[city]</td>
<td>key[aero]</td>
</tbody>
</table>


and create a link to get specific object table, how can I do that?

<html>
<body>
<p><a hr ef="/card">card</a></p> """which gives a3 value"""
<p><a href="/card">card</a></p>"""which gives a5 value"""
</body>
</html>

• In the first line your dictionaries are actually lists. Later a3 and a5 are invalid. – Klaus D. Feb 13 at 3:08
• The edit did not improve it. – Klaus D. Feb 13 at 3:35
• They are all lists (not dictionaries), two of them have a dictionary as the only item. – Klaus D. Feb 13 at 3:45