有没有办法直接从带有WTForms的html标签中提取数据
在WTForms文档中你必须放
{% from "_formhelpers.html" import render_field %}
<form method=post>
<dl>
{{ render_field(form.username) }}
{{ render_field(form.email) }}
{{ render_field(form.password) }}
{{ render_field(form.confirm) }}
{{ render_field(form.accept_tos) }}
</dl>
<p><input type=submit value=Register>
</form>
在注册页面上(我试图避免)
在主__init__.py
from wtforms import Form, BooleanField, StringField, PasswordField, validators
class RegistrationForm(Form):
username = StringField('Username', [validators.Length(min=4, max=25)])
email = StringField('Email Address', [validators.Length(min=6, max=35)])
password = PasswordField('New Password', [
validators.DataRequired(),
validators.EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
accept_tos = BooleanField('I accept the TOS', [validators.DataRequired()])
到目前为止我尝试了但是没有工作
name = TextField(request.form['username'], [validators.Length(min=2, max=20)])
email = TextField(request.form['email'], [validators.Length(min=6, max=35)])
password = PasswordField(request.form['password1'], [
validators.DataRequired(),
validators.EqualTo('confirmpw', message='Passwords must match')
])
confirmpw = PasswordField(request.form['password2'])
accept_tos = BooleanField('I accept the TOS', [validators.DataRequired()])
我的HTML
<form method=post>
<dl>
<dt>Name:
<dd><input type=text name=username >
<dt>email:
<dd><input type=email name=email>
<dt>Password:
<dd><input type=password name=password1 >
<dt>confrim Password:
<dd><input type=password name=password2 >
</dl>
<p><input type=submit value="register" >
</form>