I know using form_extra_fields can add an extra field in flask-admin. But how can I make it 'required'? Thanks in advance.
我知道使用form_extra_fields可以在flask-admin中添加一个额外的字段。但是我怎么能让它“需要”?提前致谢。
form_extra_fields = {
'password2': PasswordField('Password')
}
2 个解决方案
#1
5
Thanks a lot, Mech. Actually I figured out a simpler way:
非常感谢,Mech。其实我想出了一个更简单的方法:
from wtforms import validators
form_extra_fields = {
'password2': PasswordField('password',[validators.DataRequired()])
}
#2
3
You can use WTForms. See example below, pulled from Flask's documentation:
你可以使用WTForms。请参阅下面的示例,从Flask的文档中提取:
from wtforms import Form, BooleanField, TextField, PasswordField, validators
class RegistrationForm(Form):
username = TextField('Username', [validators.Length(min=4, max=25)])
email = TextField('Email Address', [validators.Length(min=6, max=35)])
password = PasswordField('New Password', [
validators.Required(),
validators.EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
accept_tos = BooleanField('I accept the TOS', [validators.Required()])
See the link for the other snippets (view, template, etc).
查看其他代码段的链接(视图,模板等)。
#1
5
Thanks a lot, Mech. Actually I figured out a simpler way:
非常感谢,Mech。其实我想出了一个更简单的方法:
from wtforms import validators
form_extra_fields = {
'password2': PasswordField('password',[validators.DataRequired()])
}
#2
3
You can use WTForms. See example below, pulled from Flask's documentation:
你可以使用WTForms。请参阅下面的示例,从Flask的文档中提取:
from wtforms import Form, BooleanField, TextField, PasswordField, validators
class RegistrationForm(Form):
username = TextField('Username', [validators.Length(min=4, max=25)])
email = TextField('Email Address', [validators.Length(min=6, max=35)])
password = PasswordField('New Password', [
validators.Required(),
validators.EqualTo('confirm', message='Passwords must match')
])
confirm = PasswordField('Repeat Password')
accept_tos = BooleanField('I accept the TOS', [validators.Required()])
See the link for the other snippets (view, template, etc).
查看其他代码段的链接(视图,模板等)。