在form表单中添加file;
<form action={
{
url_for('download')}} method='POST' enctype="multipart/form-data">
<input type="file" name='file'> <br>
<button type="submit">Submit</button>
</form>
app.py中使用request.files()得到file;
别忘了method=[“POST”];
from flask import Flask,render_template,request,send_file #得到email by request
app=Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/download', methods=['POST'])
def download():
if request.method=='POST':
file=request.files["file"] #input里的file name
print(file.read())
print(file) #<FileStorage: 'Sample.csv' ('application/vnd.ms-excel')>
print(type(file)) #<class 'werkzeug.datastructures.FileStorage'>
return render_template('home.html')
if __name__ =='__main__':
app.debug=True
app.run(port=5001)