flask 上传 xlsx 等文件并保存:
from flask import Flask, request, jsonify
import pandas as pd
app=Flask(__name__)
@app.route("/upload", methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
print(request.files['file'])
f = request.files['file']
with open("./tmp.xlsx", 'wb') as fp:
fp.write(f.read())
# data_xls = pd.read_excel(f)
# return data_xls.to_html()
return '''
<!doctype html>
<title>Upload an excel file</title>
<h1>Excel file upload (csv, tsv, csvz, tsvz only)</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file><input type=submit value=Upload>
</form>
'''@app.route("/export", methods=['GET'])
def export_records():
return
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
正文完