django中视图函数中装饰器

前端之家收集整理的这篇文章主要介绍了 django中视图函数中装饰器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

方法

给指定方法

from django.utils.decorators import method_decorator

class xx(View):
    @method_decorator(装饰器方法)
    def post(self,request):
                    ...

方法

给dispatch加

@method_decorator(装饰器方法)
def dispatch(self,request,*args,**kwargs):
    ...

方法

给类加

from django.utils.decorators import method_decorator
@method_decorator(装饰器方法,name="get")
@method_decorator(装饰器方法,name="post")
class xxxx(View):
    ... 

猜你在找的Django相关文章