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

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>
<thead>
<th>car</th>
<th>city</th>
<th>aero</th>
</thead>
{{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>
share|improve this question
  • 1
    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

1 Answer 1

active oldest votes
up vote 0 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310735 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO