Clarify semantics of app context #5507
Unanswered
wwwillchen
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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
g
to maintain request-specific context (essentially the UI data for the current request), see call site exampleI read through the Flask docs and am not 100% sure whether this is an appropriate use of
g
.From https://flask.palletsprojects.com/en/3.0.x/api/#flask.g:
This makes it sound like
g
is suitable as I'm trying to store information about the current request.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
g
, it's to a local-specific app context and not some more global app context that persists across requests.Beta Was this translation helpful? Give feedback.
All reactions