0 votes
in Python Flask by

What is the g object in Flask? How does it differ from the session object?

1 Answer

0 votes
by

Flask’s g object is used as a global namespace for holding any data during the application context. g object is not appropriate for storing the data between requests. The letter g, in a sense, stands for global.

In situations, when you need to keep global variables during an application context, then rather than creating your global variable, it is best to use the g object as each request in Flask has a separate g object. Flask’s g object saves us from accidental modifications of self-defined global variables.

Related questions

0 votes
asked Feb 24 in Angular by SakshiSharma
0 votes
asked Nov 18, 2021 in BlockChain by Robin
...