1. 我们用 wrapper了WTForms的Flask-WTF扩展来处理表单生成和验证。
2. Cross-Site Request Forgery (CSRF) 保护
配置config,‘SECRET_KEY‘
3. Form class definition
from flask.ext.wtf import Form from wtforms import StringField, SubmitField from wtforms.validators import Required class NameForm(Form): name = StringFiled('what is your name?', validators=[Required]) submit = SubmitFiled('Submit')
4. 标准 Fields
StringField TextAreaField PasswordField HiddenField DateField Text field accepts a dattime.date value in a given format DateTimeField IntegerField DecimalField FloatField BooleanField RadioField SelectField SelectMultipleField FileField SubmitField FormField FieldList
5. 标准validators
卧槽,这个有点老,还是看WTForms的文档去吧。
Email EqualTo 密码验证时很有用 IPAddress Length NumberRange 验证value是否在一个数值范围 Optional Required 字段包含数据 Regexp 正则验证 URL AnyOf NoneOf
6.
《Flask Web Development》学习笔记---chapter4 Web Forms
时间: 2024-10-06 15:14:34