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):

 

posted @ 2018-08-28 22:27  EngineTang  阅读(117)  评论(0编辑  收藏  举报