This is the code I have written in python flask to upload a excel file :
from flask import Flask,render_template,request
import csv
app=Flask(__name__,template_folder="/Users/viru/Downloads/Login_v5")
@app.route("/",methods=['GET','POST'])
def upload():
return render_template("fileform.html")
@app.route("/process",methods=['GET','POST'])
def batchPass():
if request.method == "POST":
l=[]
f=request.form["xlfile"]
with open(f) as file:
csvfile=csv.reader(file)
for row in csvfile:
l.append(row)
return f"<h1></h1>"
if __name__ == "__main__":
app.run(debug=True)
fileform.html:
<form action="process" method="post" enctype="multipart/form-data" >
<input type="file" name="xlfile" id="">
<button type="submit" class="btn btn-primary">Submit</button>
But when I upload the file and click submit I get this error :
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'xlfile
Please help me solve the issue.
note
/*
I did the coding as in [https://www.youtube.com/watch?v=tJKHrLzcopo] video
*/
Aucun commentaire:
Enregistrer un commentaire