g对象
g对象
# g,global,当请请求的全局
#g对象特点:session对象是可以跨request的,只要session还未失效,不同的request的请求会获取到同一个session,
# 但是g对象不是,g对象不需要管过期时间,请求一次g对象就改变了一次,或者重新赋值了一次
from flask import Flask, g, request
app = Flask(__name__)
@app.before_request
def before():
# g对象的作用就是怕你改变了全局的request里面的属性
g.name = 'tank'
@app.route('/')
def index():
print(g.name)
return 'ok'
@app.route('/index')
def index1():
print(g.name)
return 'ok1'
if __name__ == '__main__':
app.run()
Only you can control your future
You're not alone. You still have family,peopel who care for you and want to save you.