码迷,mamicode.com
首页 > 其他好文 > 详细

消息提示

时间:2018-02-18 15:21:30      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:hello   lan   import   turn   else   ase   route   ext   lease   

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>

 

消息提示

标签:hello   lan   import   turn   else   ase   route   ext   lease   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!