Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ITAC | Flask - Basic Flask

ITAC | Flask - Basic Flask

ITAC | Flask - Basic Flask

racterub

May 19, 2020
Tweet

More Decks by racterub

Other Decks in Technology

Transcript

  1. 起⼿式 from flask import Flask app = Flask(__name__) @app.route("/") def

    hello(): return "Hello World!" if __name__ == "__main__": app.run() 6
  2. GET param @app.route("/get/") def get(): name = request.args.get("name") passwd =

    request.args.get("passwd") return "name: %s, password: %s" % (name, passwd) 8
  3. POST param @app.route("/post/") def post(): name = request.form["name"] passwd =

    request.form["passwd"] return "name: %s, password: %s" % (name, passwd) 9
  4. Login @app.route("/login/", methods=["POST", "GET"]) def login(): if request.method == "POST":

    try: if (request.form["username"] == "test" and request.form["password"] == "test"): session["user"] = request.form["username"] return "Success" else: return redirect(url_for("login")) except ValueError: return "Something broke", 400 else: return render_template("login.html") 10