[英]Printing a CSV table on a webpage using flask
So I tried using pandas to create the dataframe and finally convert it to an html file and put the data in dataset.html. 因此,我尝试使用pandas创建数据框,最后将其转换为html文件,然后将数据放入dataset.html中。 So I left the dataset.html file empty. 因此,我将dataset.html文件留为空白。 But when I run this, the '/dataset' page is empty. 但是当我运行它时,“ /数据集”页面为空。 How do I fix this? 我该如何解决?
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)
您应该具有data=table.to_html()
to_html()
是一个函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.