From 4036f1c1211910d84fab848d9550652d7df767fe Mon Sep 17 00:00:00 2001 From: caitinggui <1029645297@qq.com> Date: Fri, 19 Jan 2018 16:20:07 +0800 Subject: [PATCH 1/2] update class_based_views --- docs/sanic/class_based_views.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/sanic/class_based_views.md b/docs/sanic/class_based_views.md index ace8bf9c..b7a5a101 100644 --- a/docs/sanic/class_based_views.md +++ b/docs/sanic/class_based_views.md @@ -92,10 +92,27 @@ class ViewWithDecorator(HTTPMethodView): def get(self, request, name): return text('Hello I have a decorator') + def post(self, request, name): + return text("Hello I also have a decorator") + app.add_route(ViewWithDecorator.as_view(), '/url') ``` -#### URL Building +But if you just want to decorator some functions and not all functions, you can use as followed. + +```python +class ViewWithSomeDecorator(HTTPMethodView): + + @staticmethod + @some_decorator_here + def get(request, name): + return text("Hello I have a decorator") + + def post(self, request, name): + return text("Hello I don't have any decorators") +``` + +## URL Building If you wish to build a URL for an HTTPMethodView, remember that the class name will be the endpoint that you will pass into `url_for`. For example: From ec4339bd47659df6e3dcab3c5e75f31ec5d5cad7 Mon Sep 17 00:00:00 2001 From: caitinggui <1029645297@qq.com> Date: Wed, 24 Jan 2018 09:02:07 +0800 Subject: [PATCH 2/2] update description --- docs/sanic/class_based_views.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sanic/class_based_views.md b/docs/sanic/class_based_views.md index b7a5a101..c3304df6 100644 --- a/docs/sanic/class_based_views.md +++ b/docs/sanic/class_based_views.md @@ -98,7 +98,7 @@ class ViewWithDecorator(HTTPMethodView): app.add_route(ViewWithDecorator.as_view(), '/url') ``` -But if you just want to decorator some functions and not all functions, you can use as followed. +But if you just want to decorate some functions and not all functions, you can do as follows: ```python class ViewWithSomeDecorator(HTTPMethodView):