zoukankan      html  css  js  c++  java
  • 消息提示

    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>
  • 相关阅读:
    JSP九大内置对象的作用和用法总结(转)
    Java web的几种异常处理 (转)
    response.getWriter().write()与out.print()的区别(转)
    【JavaWeb】Session(转)
    java web中cookies的用法 转
    1123
    1120
    jsp 内置对象
    include与jsp:include区别
    11.24作业1
  • 原文地址:https://www.cnblogs.com/themost/p/8452789.html
Copyright © 2011-2022 走看看