django CBV模式下如何去掉csrf验证

方式一:
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
from django.views import View
class Goods_views(View):
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super(Goods_views,self).dispatch(request, *args, **kwargs)
  def post(request):
    pass
注:上述代码除了类名(Goods_views)可以替换。其他均不可更改。


方式二:
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
from django.views import View
@method_decorator(csrf_exempt,name='dispatch')
class Goods_views(View):
  def post(request):
    pass


posted @ 2018-08-31 17:21  xsan  阅读(736)  评论(0编辑  收藏  举报