add an necessary import for better understanding
add `from sanic.response import redirect`
This commit is contained in:
parent
b8bb77eff6
commit
ef26cb283b
|
@ -138,6 +138,8 @@ app.add_route(person_handler2, '/person/<name:[A-z]>', methods=['GET'])
|
||||||
Sanic provides a `url_for` method, to generate URLs based on the handler method name. This is useful if you want to avoid hardcoding url paths into your app; instead, you can just reference the handler name. For example:
|
Sanic provides a `url_for` method, to generate URLs based on the handler method name. This is useful if you want to avoid hardcoding url paths into your app; instead, you can just reference the handler name. For example:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from sanic.response import redirect
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
async def index(request):
|
async def index(request):
|
||||||
# generate a URL for the endpoint `post_handler`
|
# generate a URL for the endpoint `post_handler`
|
||||||
|
@ -145,7 +147,6 @@ async def index(request):
|
||||||
# the URL is `/posts/5`, redirect to it
|
# the URL is `/posts/5`, redirect to it
|
||||||
return redirect(url)
|
return redirect(url)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/posts/<post_id>')
|
@app.route('/posts/<post_id>')
|
||||||
async def post_handler(request, post_id):
|
async def post_handler(request, post_id):
|
||||||
return text('Post - {}'.format(post_id))
|
return text('Post - {}'.format(post_id))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user