flask 简单注册页面

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户注册页面</title>
</head>
<body>
<h1>用户注册</h1>
<form action="" 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>

py

from flask import Flask
from flask import make_response, request, render_template
import setting,json

app = Flask(__name__)
app.config.from_object(setting)  #引用的配置文件


users=[]   #将注册的信息保存在列表中
@app.route('/register',methods = ["Post","Get"])
def register():

    # 请求的方式
    if request.method == "POST":
        username = request.form.get("username")
        password = request.form.get("password")
        repassword = request.form.get("repassword")
        if password == repassword:
            user = {"username":username,"password":password}
            users.append(user) 
            print(users)
            return '注册成功'
        else:
            return '密码不一致'
    else:
        return render_template("register.html")

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5000)

 

posted @ 2021-09-08 10:31  fat_girl_spring  阅读(72)  评论(0编辑  收藏  举报