从 MongoEngine 模型中自动生成 WTForms 获取数据
Getting Data from automatically generates WTForms from MongoEngine models
提交后如何从 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>
@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)
提交后如何从 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>
@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)