cbv fbv decorator
Posted infaaf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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):
以上是关于cbv fbv decorator的主要内容,如果未能解决你的问题,请参考以下文章