我有app.py檔案:
from flask import Flask, request, render_template
import pandas as pd
app = Flask(__name__)
@app.route('/upload', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
df = pd.read_csv(request.files.get('file'))
return render_template('upload.html', shape=df.shape)
return render_template('upload.html')
if __name__ == '__main__':
app.run(debug=True)
和upload.html檔案:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
Shape is: {{ shape }}
</body>
</html>
和dummy.csv檔案:
id,name,surname
1,John,Doe
2,Jane,Doe
我想在上傳 csv 檔案時顯示資料的形狀。我無法通過我的實作獲得資料的形狀。我感謝任何提示/幫助。
uj5u.com熱心網友回復:
這是解決方案:
創建一個模板檔案夾并將您的 upload.html 檔案放在模板檔案夾中。由于模板檔案夾中沒有它,flask 正在回傳 jinga2 template not found 錯誤。
就像所有影像都需要在靜態檔案夾中一樣,所有 html 模板都需要在模板檔案夾中才能使您的應用程式正常作業。
希望這可以幫助!
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/526740.html
標籤:Python熊猫烧瓶
上一篇:創建動態燒瓶路線
