赞
踩
- from flask import Flask, render_template, request
- from flask_wtf import FlaskForm
- from wtforms.fields.simple import StringField, PasswordField, SubmitField
- from wtforms.validators import DataRequired, EqualTo
-
- app = Flask(__name__)
-
- app.config['SECRET_KEY'] = ';kjlasdklja'
-
-
- # 定义表单模型类
- class Register(FlaskForm):
- username = StringField(label='用户名', validators=[DataRequired("用户名不能为空")])
- password = PasswordField(label='密码', validators=[DataRequired("密码不能为空")])
- password2 = PasswordField(label='再一次输入密码', validators=[DataRequired("密码不能为空"), EqualTo("password")])
- sumbit = SubmitField(label='提交')
-
-
- @app.route("/register", methods=['POST', 'GET'])
- def register():
- # 创建表单对象
- form = Register()
- if request.method == "GET":
- return render_template("register.html", form=form)
- if request.method == "POST":
- # 从前端获取数据
- if form.validate_on_submit():
- username = form.username
- password = form.password
- password2 = form.password2
- print(username)
- print(password)
- print(password2)
- return render_template("register.html", form=form)
- else:
- return render_template('404.html')
-
-
- if __name__ == '__main__':
- app.run()
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- Hello world
- <br>
- {{ data.name }}
- <br>
- {{ data.age }}
- <br>
- {{ data.list[1] }}
- <br>
- {{ "hello_world" | upper | replace('HELLO','HI') }}
- <br>
- {{ data.list | li2 }}
-
- </body>
- </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。