Merge pull request #480 from subyraman/patch-2
Add documentation about `request.app`
This commit is contained in:
commit
13f81e9a6f
|
@ -69,6 +69,23 @@ The following variables are accessible as properties on `Request` objects:
|
||||||
|
|
||||||
- `ip` (str) - IP address of the requester.
|
- `ip` (str) - IP address of the requester.
|
||||||
|
|
||||||
|
- `app` - a reference to the Sanic application object that is handling this request. This is useful when inside blueprints or other handlers in modules that do not have access to the global `app` object.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from sanic.response import json
|
||||||
|
from sanic import Blueprint
|
||||||
|
|
||||||
|
bp = Blueprint('my_blueprint')
|
||||||
|
|
||||||
|
@bp.route('/')
|
||||||
|
async def bp_root(request):
|
||||||
|
if request.app.config['DEBUG']:
|
||||||
|
return json({'status': 'debug'})
|
||||||
|
else:
|
||||||
|
return json({'status': 'production'})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Accessing values using `get` and `getlist`
|
## Accessing values using `get` and `getlist`
|
||||||
|
|
||||||
The request properties which return a dictionary actually return a subclass of
|
The request properties which return a dictionary actually return a subclass of
|
||||||
|
|
Loading…
Reference in New Issue
Block a user