From: Liam O'Boyle Date: Wed, 4 Sep 2019 01:56:26 +0000 (+1000) Subject: Add "accessing the app instance" to docs/application.md X-Git-Tag: 0.12.11~18^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F620%2Fhead;p=thirdparty%2Fstarlette.git 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`. --- diff --git a/docs/applications.md b/docs/applications.md index 5c30365f..44426448 100644 --- a/docs/applications.md +++ b/docs/applications.md @@ -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.