add handler name to request as endpoint

This commit is contained in:
Raphael Deem
2017-10-16 22:40:21 -07:00
parent c5cdcf0f95
commit 75f2180cb1
4 changed files with 32 additions and 1 deletions

View File

@@ -120,3 +120,19 @@ args.get('titles') # => 'Post 1'
args.getlist('titles') # => ['Post 1', 'Post 2']
```
## Accessing the handler name with the request.endpoint attribute
The `request.endpoint` attribute holds the handler's name. For instance, the below
route will return "hello".
```python
from sanic.response import text
from sanic import Sanic
app = Sanic()
@app.get("/")
def hello(request):
return text(request.endpoint)
```