Clarify semantics of app context #5507
-
Thanks for building Flask! I'm one of the maintainers of https://github.com/google/mesop which is a Python UI framework built on Flask. Mesop uses I read through the Flask docs and am not 100% sure whether this is an appropriate use of From https://flask.palletsprojects.com/en/3.0.x/api/#flask.g:
This makes it sound like From https://flask.palletsprojects.com/en/3.0.x/appcontext/:
This suggests that an application context is always created inside the scope of a request. However, https://flask.palletsprojects.com/en/3.0.x/api/#flask.ctx.AppContext states:
This seems to suggest an application context is not always created inside the scope of a request. These two docs seem to contradict one another (or perhaps I'm mis-reading it). Any clarification would be helpful. One of the complexities with our use case is that other developers are building on top of Mesop and could create app contexts, and I want to make sure that when I'm binding a value to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Beta Was this translation helpful? Give feedback.
g
is the appropriate place to store per-request data. For extensions, we recommend using a prefix like_extension_name_
as a namespace to avoid any potential name conflicts. See https://flask.palletsprojects.com/en/3.0.x/extensiondev/ and specifically https://flask.palletsprojects.com/en/3.0.x/extensiondev/#data-during-a-request for extension dev docs about this.