Vipin Maurya :
I'm trying to add data in dictionary through form using post method. But it's not working. form is working with get method but not post. I read many similar posts but could'nt understand so posting here. Please help me to locate the problem and solve it.
Python Code
@app.route('/add_card',methods=["GET","POST"])
def add_card():
if request.method == "POST":
card = {"question": request.form['question'],
"answer": request.form['answer']}
db.append(card)
return redirect(url_for('card_view',index=len(db)-1))
else:
return render_template("add_card.html")
Form code:
<form methods=" POST">
<p>
Question:
<input type="text" name="=question">
</p>
<p>
Answer:
<input type="text" name="'answer">
</p>
<button type="submit">
Create
</button>
</form>
Derlin :
Replace:
<form methods=" POST">
with:
<form method="POST">
You have an extra s, making the form use GET to submit.
As an aside, if you have many forms in your app, Flask-WTF may become handy.