From ef26cb283b2ffa418d607edf83dc22f9a45f6594 Mon Sep 17 00:00:00 2001 From: yingshaoxo Date: Mon, 26 Feb 2018 11:24:54 +0800 Subject: [PATCH] add an necessary import for better understanding add `from sanic.response import redirect` --- docs/sanic/routing.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/sanic/routing.md b/docs/sanic/routing.md index 98179e17..e9cb0aef 100644 --- a/docs/sanic/routing.md +++ b/docs/sanic/routing.md @@ -138,13 +138,14 @@ app.add_route(person_handler2, '/person/', 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: ```python +from sanic.response import redirect + @app.route('/') async def index(request): # generate a URL for the endpoint `post_handler` url = app.url_for('post_handler', post_id=5) # the URL is `/posts/5`, redirect to it - return redirect(url) - + return redirect(url) @app.route('/posts/') async def post_handler(request, post_id):