'Flask: ImmutableMultiDict([]) - Why is it empty? [duplicate]
I'm trying to transfer formdata from html into a database, but when i try to send the content i got an empty Dict.
html looks like this:
...
<form id="set" action="/settings" method="POST">
<h3>Name</h3>
<input type="text" class="input" name="name" id="name" value={{name}}>
<h3>Email</h3>
<input type="text" class="input" name="email" id="email" value={{email}}>
<br><button class="btn" type="submit" form="set">Update</button>
</form>
...
pythoncode looks like this:
...
@app.route("/settings", methods=['POST'])
@login_required
def settings():
if request.method == 'POST':
name = request.form['name']
email = request.form['email']
...
then i got this error:
werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'name'
so i printed out the dict
ImmutableMultiDict([])
and saw it was empty. But why? What do i have to change?
Btw i'm using multiple forms in this html, but i dont think this is the problem.
Solution 1:[1]
I have found the solution. Sorry, the code above is working. I haven't shared the full code. I have multiple forms in my html and not all input form tags had a name.
wrong:
<input type="text">
correct:
<input type="text" name="pw" id="pw">
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MaxW |
