Issue
I'm making a registration form for vendors in my ecom website and, I'm getting a bad request error while doing a post request. I tried to find out what's causing this error, but everything seems to be fine. I've used a template similar to this and it was working fine, but I don't know what's wrong with this one. Take a look at my code and please help me find out the problem.
HTML code :
<div class="col">
<form action="{{ url_for('Vendor_registration') }}" method="post" style="padding-top:1%;">
<div class="form-group">
<label for="first">First Name:</label>
<input type="text" name="first_name" class="form-control" placeholder="For eg : Andrew" id="first" maxlength="15">
</div>
<div class="form-group">
<label for="middle">Middle Name:</label>
<input type="text" name="middle_name" class="form-control" placeholder="For eg : Jason" id="middle" maxlength="15">
</div>
<div class="form-group">
<label for="last">Last Name:</label>
<input type="text" name="last_name" class="form-control" placeholder="For eg : Sebastian" id="last" maxlength="15">
</div>
<div class="form-group">
<label for="contact">Contact Number:</label>
<input type="text" name="contact_no" class="form-control" placeholder="For eg : 0123456789" id="contact" maxlength="10">
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" name="email" class="form-control" placeholder="For eg : [email protected]" id="email" maxlength="30">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" name="password" class="form-control" placeholder="********" id="pwd" maxlength="15">
</div>
<div class="form-group">
<label for="shop">Shop Name:</label>
<input type="text" name="shop_name" class="form-control" placeholder="For eg : abc store" id="shop" maxlength="15">
</div>
<div class="form-group">
<label for="certificate">Shop Certificate:</label>
<input type="file" name="image" class="form-control-file border" id="certificate">
</div>
<div class="form-group">
<label for="account">Bank Account number:</label>
<input type="text" name="account_no" class="form-control" id="account" maxlength="20">
</div>
<div class="form-group">
<label for="upi">UPI ID:</label>
<input type="text" name="upi_id" class="form-control" id="upi" maxlength="15">
</div>
<button type="submit" class="btn btn-success btn-block">Submit</button>
</form>
</div>
Python code :
@app.route("/vendor_register", methods=["GET","POST"])
def Vendor_registration():
email=str(request.form.get("email"))
first_name=str(request.form.get("first_name"))
middle_name=str(request.form.get("middle_name"))
last_name=str(request.form.get("last_name"))
shop_name=str(request.form.get("shop_name"))
phone_no=str(request.form.get("contact_no"))
password=str(request.form.get("password"))
account_no=str(request.form.get("account_no"))
upi_id=str(request.form.get("upi_id"))
shop_certificate=" "
file=request.files["image"]
return "done"
logs :
└─$ flask run
* Serving Flask app "application.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [20/Mar/2021 03:13:46] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [20/Mar/2021 03:13:48] "POST /vendor_registration HTTP/1.1" 200 -
127.0.0.1 - - [20/Mar/2021 03:13:58] "POST /vendor_register HTTP/1.1" 400 -
^C
Solution
I got the answer. I actually forgot to mention the mime type which is ' enctype="multipart/form-data" ' in the form, because there was an image also. Now the problem is solved.
Answered By - stormcloak
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.