如何在提交后从WTForms表单中获取数据?
型号:
class User(db.Document):
name = db.StringField(required=True)
UserForm = model_form(User)
查看:
@app.route('/submit', methods=('GET', 'POST'))
def add_user():
form = UserForm()
if form.form.validate_on_submit():
print(form.name.data)
return render_template('user.html', form=form)
以下是HTML格式:
<form method="POST" action="">
{{ form.hidden_tag() }}
{{ form.name.label }} {{ form.name(size=20) }}
<input type="submit">
</form>
答案 0 :(得分:0)
@app.route('/submit', methods=('GET', 'POST'))
def add_user():
form = UserForm(request.form)
if request.method == 'POST' and form.validate():
print(form.name.data)
return render_template('user.html', form=form)