Answer the question
In order to leave comments, you need to log in
How to fix error in flask request.form?
Hello. i have this code:
<label>
<textarea name="recipe" rows="15" cols="55"></textarea>
</label>
<form action="/save" method="POST">
<input type="submit" value="Сохранить">
</form>
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template("create.html")
@app.route('/save', methods=['POST', 'GET'])
def do_save():
if request.method == 'POST':
recipe = request.form['recipe']
print(recipe)
else:
print("GET")
return render_template('index.html')
recipe = request.form.get('recipe')
Answer the question
In order to leave comments, you need to log in
Because your text field is not attached to the form, add a id
pointer to the form to the form and to the text field:
<label>
<textarea name="recipe" rows="15" cols="55" form="some-form"></textarea>
</label>
<form id="some-form" action="/save" method="POST">
<input type="submit" value="Сохранить">
</form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question