#coding=utf-8 from flask import Flask from flask import request from flask import redirect from flask import url_for from flask import render_template from flask import session app = Flask(__name__) @app.route("/home") def hello_world(): return "hello world" @app.route("/user", methods=["GET", "POST"]) def check_user(): if request.method == "POST": username = request.form.get("username") session["user"] = username return redirect(url_for("hello_world")) elif request.method == "GET": if "user" in session: return redirect(url_for("hello_world")) return "Please register first!" app.secret_key = "YouWillNeverGuessWhatIThink" if __name__ == '__main__': app.run(debug=True)