提交后如何从 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>