Posting Data on Flask via form is giving 400 Bad Request
Ah, I think I see it: You only set the id
but not the name
for the input
element. Yet the name
is used in the form data that is sent to the server. This causes a KeyError
at request.form['query']
which causes the 400 error.
Besides what @Robin Krahl said, You also should add enctype="multipart/form-data"
in your form. So the code maybe like this:
<form id="form1" action="/final" method="post" enctype="multipart/form-data"> <input id='query' type="text"> <button type="submit" onClick='sub()'>Submit ยป</button></form>"