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)
上一篇:十三 .Flask wtforms组件和选择框动态数据实时更新


下一篇:Shi-Tomasi角点检测