django中視圖函數中裝飾器

方法一

給指定方法加python

from django.utils.decorators import method_decorator

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

方法二

給dispatch加django

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

方法三

給類加post

from django.utils.decorators import method_decorator
@method_decorator(裝飾器方法, name="get")
@method_decorator(裝飾器方法, name="post")
class xxxx(View):
    ...
相關文章
相關標籤/搜索