g对象
g对象
g对象就是一个容器,能够多次取值
from flask import Flask,g,request
app = Flask(__name__)
@app.before_request
def be():
#request.name="cxw is big"
if request.path=="/login":
g.name="cxw is big"
def set_g():
g.name = "cxw is big"
@app.route("/")
def index():
set_g()
print("视图1",g.name)
# print("视图2", g.name)
return "ok"
@app.route("/login")
def login():
print("login视图1", g.name)
return "login"
@app.after_request
def af(response):
print("after_request", g.name)
return response
if __name__ == '__main__':
app.run()