flask-笔记-form组件
作者:互联网
form 表单导入
from flask_wtf import FlaskForm
# 生成标签的类
from wtforms import StringField , PasswordField,SubmitField
# 添加校验规则
from wtforms.validators import DataRequired,EqualTo
app = Flask(__name__)
app.config['SECRET_KEY'] = '123'
class RegisterForm(FlaskForm):
name = StringField(lebal='用户名',validators[DataRequired('必填')])
password = StringField(lebal='密码',validators[DataRequired('必填')])
password2 = StringField(lebal='再次输入密码',validators[DataRequied('必填'),EqualTo('两次输入不一致')])
submit = SubmitField(label='注册')
@app.route('/index/',methods=['GET','POST'])
def index():
registerform = RegisterForm()
if request.method == 'POST':
if registerform.validate_on_submit():
name = registerform.name.data
pwd = registerform.password.data
pwd2 = registerform.password2.data
return 'success'
return render_template('index.html',registerform=registerform)
if __name__=='__main__':
app.run(debug=True)
标签:__,StringField,name,form,flask,app,validators,组件,registerform 来源: https://blog.csdn.net/weixin_42766128/article/details/100586169