Using Python Flask app to render a html table with 'for' loop implementation. But the data doesn't render giving a blank <tr><tr>.
I am converting a dataframe to html by passing a dff.to_html() from render_template and retrieving the table in html in a 'for' loop to display.
Python code:
return render_template('index.html', table = dff.head(50).to_html())
html code:
<table>
<tbody>
{% for row in table %}
<tr>
<td>{{row.name}}</td>
<td>{{row.link_to_detail}}</td>
<td>{{row.link}}</td>
<td><input name ="get poster" type="submit" value={{row['id']}}></td>
</tr>
{% endfor %}
</tbody>
</table>
Actual result is
<tr>
<td></td>
<td></td>
<td></td>
<td><input name="get poster" type="submit" value=""></td>
</tr>
Expected result :
<tr>
<td>name</td>
<td>link_to_detail</td>
<td>link</td>
<td><input name="get poster" type="submit" value=""></td>
</tr>
'''
dff.head(50).to_html() returns an html table, not a python object.
This html table is actually a string, and you are iterating over characters (row), which do not have any attributes called name, link or link_to_detail...
I'll be able to complete this answer if you post a sample of your
dffdataframe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With