ChuannBlog

fisrt FLask

from flask import Flask, render_template, request, session, redirect
app = Flask(__name__)
app.secret_key = "jksdhfaj32jhgrfhjgvikhjg32hufgvhxzgv78432hjsvcsgv"

@app.route("/login/", methods=['GET', 'POST'])
def login():
    if request.method == "GET":
        return render_template('login.html')
    else:
        if not request.form.get("username") == "wusir" and request.form.get("password") == "123":
            return render_template('login.html', msg="用户名或密码错误")
        session["user_info"] = {"username": "武沛齐"}
        return redirect('/index/')

@app.route("/index/", methods=["GET", ])
def index():
    return render_template('index.html', **{'msg': session.get("user_info")})

if __name__ == '__main__':
    app.run()