如何表示从Flask传递到HTML的动态数据


@app.route('/detection')
def detection():
data = similarity_fun()
return render_template("detection.html", data = data)

我正在将数据传递到detection.html(数据是元组列表的形式,例如([('1.txt','20.txt',74(,('2.txt','20.txt',100(,('1.tx','2.txt’,74(](。

这个数据列表可以有元组的数量,这取决于用户给出的输入,所以长度不是固定的。我想以图表的形式表示传递给detection.html的数据,其中第一个和第二个元素表示图表中条形图的名称,每个元组的第三个元素表示百分比。

您可以使用jinja模板动态创建html表。

<body>
<table border="1px solid black" style="width:100%" >
{% for rows in data %}
<tr> # rows will be the amount of tuples in the list
{%for columns in rows %} # iterating over the tuples
<td>
{{ columns }}
</td>
{% endfor %} # ending tuple iteration
{% endfor %} # ending list iteration
</tr>
</table>

希望这能有所帮助!

最新更新