Flask实现的功能:
- 建立用户注册表单
- 添加用户注册视图函数
- 用户注册模板
目录结构:
1.建立用户注册和登录表单:
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField
from wtforms.validators import DataRequired, Length, EqualTo, Email, ValidationError
from flask_wtf.file import FileField, FileAllowed, FileRequired
from app.models import User
from app.extensions import photos
# 用户注册表单
class RegisterForm(FlaskForm):
username = StringField('用户名', validators=[DataRequired(message='用户名不能为空'), Length(6, 12, message='用户名只能在6~12个字符之间')])
password = PasswordField('密码', validators=[DataRequired(message='密码不能为空'), Length(6, 20, message='密码只能在6~20个字符之间')])
confirm = PasswordField('确认密码', validators=[EqualTo('password', message='两次密码不一致')])
email = StringField('邮箱', validators=[Email(message=