标签:class rect ppi color import template bsp cookie flask
一、session
除请求对象之外,还有一个 session 对象。它允许你在不同请求间存储特定用户的信息。它是在 Cookies 的基础上实现的,并且对 Cookies 进行密钥签名要使用会话,你需要设置一个密钥。
from flask import Flask
from flask import render_template
from flask import session
from flask import request
from flask import redirect
app = Flask(__name__)
app.config.from_mapping({"SECRET_KEY":"value"})
@app.route("/login",methods=["GET","POST"])
def login():
if request.method == "POST":
username = request.form.get("username")
password = request.form.get("password")
if username == "xiaoming" and password == "123":
# 登陆成功后设置session
session["userinfo"] = {"name":username}
return redirect("/")
return render_template("login.html")
@app.route("/")
def index():
# 获取session
print(session["userinfo"])
return "首页"
if __name__ == ‘__main__‘:
app.run()
标签:class rect ppi color import template bsp cookie flask
原文地址:https://www.cnblogs.com/st-st/p/10186826.html