Add "accessing the app instance" to docs/application.md

Along the lines of @tomchristie's suggestion in #620 but stressing the
use of `request.app`.
This commit is contained in:
Liam O'Boyle 2019-09-04 11:56:26 +10:00
parent 0e75f9f2b8
commit 730111fc33
1 changed files with 5 additions and 1 deletions

View File

@ -80,10 +80,14 @@ exceptions that occur within the application:
### Storing state on the app instance
You can store arbitrary extra state on the application instance, using the
generic `app.state` attribute. This can then be accessed in middleware or endpoints via `request.app`.
generic `app.state` attribute.
For example:
```python
app.state.ADMIN_EMAIL = 'admin@example.org'
```
### Acessing the app instance
Where a `request` is available (i.e. endpoints and middleware), the app is available on `request.app`. For other situations it can be imported from wherever it's instantiated.