cbv fbv decorator

1

from django.views.decorator import csrf_exempt,csrf_protect
from django.utils.decorators import method_docorator
from django.views import View

#@method_decorator(csrf_exempt,name='dispatch')
class AbcView(View):
    @method_decorator(csrf_exempt)
    def dispatch(self,requests,*args,**kwargs):
        return super(AbcView,self).dispatch(requests,*args,**kwargs)

    def get(self,request,):
        pass

 2

@permission_required('aptest.change_hv',login_url="/aptest/loginauth") 
def  f(request):
  pass

3

@login_required(login_url="/aptest/loginauth") #不需要再使用permission_required()装饰器
def add(request):

4


class
MyView(LoginRequiredMixin, PermissionRequiredMixin, View)

5

class LoginRequiredMixin(object):
    @method_decorator(login_required(login_url='/login/'))
    def dispatch(self,request,*args,**kwargs):
原文地址:https://www.cnblogs.com/infaaf/p/9551376.html