What is the g object in this flag?

I found this code, every time every answer, but I'm not sure where it should come from g

. What is it g

?

@app.before_request
def before_request():
  g.start = time.time()

@app.teardown_request
def teardown_request(exception=None):
    diff = time.time() - g.start
    print diff

      

+3


source to share


1 answer


g

is an object provided by Flask. It is a global namespace for storing any data that you want to use during a single application context.

from flask import g

      

Application context lasts one request / response cycle, g

not suitable for storing data across requests. Use database, redis, session or other external data source to persist data.




Note that the dev server and any webserver are already giving out sync information in the logs. If you really want to profile your code, you can use the Werkzeug Application Profiler .

+11


source







All Articles