# 1. 创建模型对象
user = User()
# 2. 给对象赋值
user.username = username
user.password = pwd
user.phone = phone
# 3. 向数据库提交数据
db.session.add(user)
db.session.commit()
# 用户注册
@blog_bp.route('/register', endpoint='register', methods=['GET', 'POST'])
def user_register():if request.method == 'POST':# 获取表单提交的内容username = request.form.get('username')pwd1 = request.form.get('password1')pwd2 = request.form.get('password2')phone = request.form.get('phone')if pwd1 == pwd2:# 存放到数据库pwd = hashlib.sha1(pwd1.encode('utf-8')).hexdigest()print(pwd)# 添加数据步骤:# 1. 创建模型对象user = User()# 2. 给对象赋值user.username = usernameuser.password = pwduser.phone = phone# 3. 向数据库提交数据db.session.add(user)db.session.commit()return redirect(url_for('blog.index'))else:return render_template('register.html', msg=' 密码不一致')return render_template('register.html')