首页 > 其他 > 详细

消息提示

时间:2018-02-18 15:19:24      阅读:212      评论:0      收藏:0      [点我收藏+]
from flask import Flask, render_template, flash, request

app = Flask(__name__)
app.secret_key = "123456"


@app.route("/")
def hello_world():
    flash("hello, mr bean")
    return render_template("index.html")


@app.route("/login", methods=["POST"])
def login():
    form = request.form
    username = form.get("username")
    password = form.get("password")
    if not username:
        flash("please input username")
        return render_template("index.html")
    if not password:
        flash("please input password")
        return render_template("index.html")
    if username == "mr bean" and password == "123456":
        flash("login success")
        return render_template("index.html")
    else:
        flash("username or password is wrong")
        return render_template("index.html")


if __name__ == __main__:
    app.run(debug=True)



#index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎登陆</title>
</head>
<body>
    <h1>welcome</h1>
    <form action="/login" method="post">
        <input type="text" name="username">
        <input type="password" name="password">
        <input type="submit" value="Submit">
    </form>
    <h2>{{ get_flashed_messages()[0] }}</h2>
</body>
</html>

 

消息提示

原文:https://www.cnblogs.com/themost/p/8452789.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!