我正在尝试在我的烧瓶应用程序中显示数据表。
这是我的示例,仅显示iris
数据集。
下面是我的app.py
from flask import flask,render_template
import seaborn as sns
import pandas as pd
iris = sns.load_dataset('iris')
app = flask(__name__)
@app.route('/')
def example():
return render_template("example.html",value=iris)
if __name__ == '__main__':
app.run(debug=True)
这里是example.html
<!doctype html>
<html>
<head></head>
<body>
<table>
<thead>
<tr>
<th>sepal_length</th>
<th>sepal_width</th>
<th>petal_length</th>
<th>petal_width</th>
<th>species</th>
</tr>
</thead>
<tbody>
{% for row in value %}
<tr>
<td>{{row[0]}}</td>
<td>{{row[1]}}</td>
<td>{{row[2]}}</td>
<td>{{row[3]}}</td>
<td>{{row[4]}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
我有这样的桌子:
sepal_length sepal_width petal_length petal_width species
s e p a l
s e p a l
p e t a l
p e t a l
s p e c i
我花了几个小时试图找出问题所在。我仍然不知道为什么它不起作用。有人知道为什么会这样吗?
此外,flask中是否可以显示漂亮的数据表,而不是使用html编码?如果没有的话,我真的会感到惊讶。