In view django function decorator

method one

To specify the method applied

from django.utils.decorators import method_decorator

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

Method Two

Add to dispatch

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

Method Three

Add to the class

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

Guess you like

Origin www.cnblogs.com/pythonywy/p/11830935.html