zoukankan      html  css  js  c++  java
  • 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()
    
    
  • 相关阅读:
    mysqldump
    设计模式
    设计模式
    设计模式
    设计模式
    PHP 调试
    PHP 调试
    Windows 下手工搭建 LNMP 环境
    设计模式
    设计模式
  • 原文地址:https://www.cnblogs.com/chanyuli/p/12153162.html
Copyright © 2011-2022 走看看