What is the role of Flask's g object?
Instruction: Describe the purpose and use of Flask's global `g` object.
Context: This question probes the candidate's understanding of Flask's `g` object, used for storing and sharing data during an application context.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
g is a namespace local to the active application context. Several functions can use it during that context without passing a resource explicitly. It is not persistent per-user storage or a process-wide cache.
For example, this Flask3.1 resource helper opens a SQLite connection lazily and closes it when the application context ends:...