【发布时间】:2017-05-24 07:47:49
【问题描述】:
所以我尝试使用 pandas 创建数据框,最后将其转换为 html 文件并将数据放入 dataset.html 中。所以我将 dataset.html 文件留空。但是当我运行它时,'/dataset' 页面是空的。我该如何解决这个问题?
from flask import Flask, render_template
import pandas as pd
app = Flask(__name__)
@app.route('/')
def home_page():
return render_template("home.html")
@app.route('/dataset')
def another_page():
table = pd.DataFrame.from_csv("Soccer.csv")
return render_template("dataset.html", data=table.to_html)
if __name__ == '__main__':
app.run(debug=True, use_reloader=True)
【问题讨论】:
-
你的 dataset.html 模板文件的内容是什么?
-
它是空的。我应该在里面放什么?我以为 data=table.to_html 会在其中添加表格的 html 代码。
-
阅读烧瓶文档。这解释得很清楚。 flask.pocoo.org/docs/0.12/quickstart/#rendering-templates
-
你需要把
{{ data | safe }}这样的东西放到模板文件中。
标签: python html csv pandas flask