Merge pull request #1887 from zevaverbach/patch-1
Before adoption: this commit came in with the history the project adopted, so no landing records it.
enumerates the states in which code is executed...
authored by Kenneth Reitz · committed by GitHub · parents 3acec5f, 863e5cc · Browse files · 1 file·+26 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+26 added−20 removed
- other:+26 added−20 removed
Provenance
- Commit
63ddf2d- Tree
a053071- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
GitHub <noreply@github.com>- Parent 1
3acec5f- Parent 2
863e5cc
1 file changed+26 added−20 removed
modified:docs/appcontext.rst+26 added-20 removed
3 unmodified lines4 =======================5 6 .. versionadded:: 0.97 8-One of the design ideas behind Flask is that there are two different9-“states” in which code is executed. The application setup state in which10-the application implicitly is on the module level. It starts when the11-:class:`Flask` object is instantiated, and it implicitly ends when the12-first request comes in. While the application is in this state a few13-assumptions are true:8+One of the design ideas behind Flask is that there are at least two 9+different “states” in which code is executed:10 15-- the programmer can modify the application object safely.16-- no request handling happened so far17-- you have to have a reference to the application object in order to18- modify it, there is no magic proxy that can give you a reference to19- the application object you're currently creating or modifying.11+1. The application setup state, in which the application implicitly is 12+on the module level. 13 21-In contrast, during request handling, a couple of other rules exist:14+ This state starts when the :class:`Flask` object is instantiated, and 15+ it implicitly ends when the first request comes in. While the 16+ application is in this state, a few assumptions are true:17 18+ - the programmer can modify the application object safely.19+ - no request handling happened so far20+ - you have to have a reference to the application object in order to21+ modify it, there is no magic proxy that can give you a reference to22+ the application object you're currently creating or modifying.23+24+2. In contrast, in the request handling state, a couple of other rules 25+exist:26+23-- while a request is active, the context local objects27+ - while a request is active, the context local objects28 (:data:`flask.request` and others) point to the current request.25-- any code can get hold of these objects at any time.29+ - any code can get hold of these objects at any time.30 27-There is a third state which is sitting in between a little bit.28-Sometimes you are dealing with an application in a way that is similar to29-how you interact with applications during request handling; just that there30-is no request active. Consider, for instance, that you're sitting in an31-interactive Python shell and interacting with the application, or a32-command line application.31+3. There is also a third state somewhere in between 'module-level' and 32+'request-handling':33 34+ Sometimes you are dealing with an application in a way that is similar to35+ how you interact with applications during request handling, but without 36+ there being an active request. Consider, for instance, that you're 37+ sitting in an interactive Python shell and interacting with the 38+ application, or a command line application.39+40 The application context is what powers the :data:`~flask.current_app`41 context local.42 43 Purpose of the Application Context101 unmodified lines