python 3.x - How do I iterate zip list in jinja2 using for loop and display values in HTML table? -
i trying iterate zip list in jinja2 , display values in html table failed @ every single try blank page, however, can display values in unordered list follows.
<ul> {% bus, info in jnjbus_info %} <li>{{bus}}</li> <li>{{info}}</li> {% endfor %} </ul> this flask/function passing values template:
@app.route('/busses') def busses(): bus_type = ['ac', 'non-ac', 'sleeper', 'non-sleeper'] bus_info = ['1010', '2020', '3030', '4040'] return render_template('busses.html', jnjbus_info=zip(bus_type, bus_info)) i'm rendering template called busses.html here's script:
<table style="width:100%"> <tr> <th>bus type</th> <th>bus information</th> </tr> {% bus, info in jnjbus_info %} <tr> <td>{{bus}}</td> <td>{{info}}</td> </tr> {% endfor %} </table>
you don't have the
<tbody> </tbody> tag in page added , works:
<table style="width:100%"> <tr> <th>bus type</th> <th>bus information</th> </tr> <tbody> {% bus, info in jnjbus_info %} <tr> <td>{{bus}}</td> <td>{{info}}</td> </tr> {% endfor %} </tbody> </table> here how looks :

Comments
Post a Comment