from flask import Flask, render_template, flash, requestapp = 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欢迎登陆 welcome
{ { get_flashed_messages()[0] }}