flask开发用户管理系统wtf版

#coding=utf-8
from flask import Flask
from flask import request
from flask import redirect
from flask import render_template
from wtforms import Form, TextField, PasswordField, validators

app = Flask(__name__)

class LoginForm(Form):
    username = TextField("username", [validators.Required()])
    password = PasswordField("password", [validators.Required()])

@app.route("/user", methods=["GET", "POST"])
def login_checked():
    myForm = LoginForm(request.form)
    if request.method == "POST":
        if not myForm.username.data:
            message = "please input your username"
            return render_template("index.html", message=message, form=myForm)
        if not myForm.password.data:
            message = "please input your password"
            return render_template("index.html", message=message, form=myForm)
        if myForm.username.data == "lala" and myForm.password.data == "123456" and myForm.validate():
            return redirect("http://www.taobao.com")
        else:
            message = "your username or password is wrong"
            return render_template("index.html", message=message, form=myForm)
    return render_template("index.html", form=myForm)


if __name__ == "__main__":
    app.run(port=8080)

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>user management</title>
</head>
<body>
    <div align="center">
    <h1>user management</h1>
        {% if message %}
        {{ message }}
        {% endif %}

    <form method="post" name="form">
        username : {{form.username}}
        <br/>
        password : {{form.password}}
        <br/>
        <input type="submit" name="submit" value="submit">
        <input type="reset" name="reset" value="reset">
    </form>
    </div>


</body>
</html>

 

转载于:https://www.cnblogs.com/themost/p/8546985.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值