Issue
I don't understand what is wrong with my code. I've tried everything but I'm getting this error:
Bad Request
The browser (or proxy) sent a request that this server could not understand.
I checked and the problam is in main.py in the line: f= request.files['file'] , so could you please tell me whats wrong with this line??? Here is my code:
main.html:
<!DOCTYPE html>
<html>
<head>
<title>excel-reader-app</title>
<link rel="icon" href="https://www.xda-developers.com/files/2018/09/microsoft-excel-logo.png">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<br>
<br>
<br>
<h1>Super Geocoder</h1>
<h3>Please upload your CSV file. The values containing addresses should be in a columm named <i>address</i> or <b>Address</b></h3>
<form action="{{url_for('success_table')}}" method="post" >
<div class="form-file"><input type="file" name="file" id="file" accept=".csv" required></div>
<div class="form-submit"><input type="submit"></div>
</form>
</body>
</html>
success_table.html:
<!DOCTYPE html>
<html></html>
main.py:
from flask import Flask, render_template, request
import os
app = Flask(__name__)
@app.route('/',methods=['GET', 'POST'])
def mainclass():
return render_template("main.html")
@app.route('/success_table', methods=['GET', 'POST'])
def success_table():
if request.method == 'POST':
print("yes")
f= request.files['file']
print("fjjf")
if f:
f.save(os.path.join(f"csvfiles", f'{f.name}'))
return render_template("success_table.html")
if __name__ == "__main__":
app.run()
Thanks in advance! my target in this code that the csv file will be saved in the directory.
Solution
When you send file
then form
needs enctype="multipart/form-data"
<form action="{{url_for('success_table')}}" method="POST" enctype="multipart/form-data">
Answered By - furas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.