创建 templates 文件夹,在该文件夹下创建 register.html 文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>欢迎注册用户</h1>
<form action="/register" method="post">
<p><input type="text" name="username" placeholder="用户名"></p>
<p><input type="password" name="password" placeholder="密码"></p>
<p><input type="password" name="repassword" placeholder="确认密码"></p>
<p><input type="submit" value="注册"></p>
</form>
</body>
</html>![](https://img2020.cnblogs.com/blog/1334255/202008/1334255-20200823111858057-348212250.png)
在 app.py 下添加
@app.route(‘/register‘, methods=[‘GET‘, ‘POST‘])
def register():
if request.method == ‘POST‘:
print(request.form.get(‘username‘))
print(request.form.get(‘password‘))
print(request.form.get(‘repassword‘))
return ‘注册成功‘
return render_template(‘register.html‘)
原文:https://www.cnblogs.com/klvchen/p/13548650.html