Django中的csrf相關裝飾器


切記:  這倆個裝飾器不能直接加在類中函數的上方

 (CBV方式)

csrf_exempt除了,csrf_protect受保護的

 
from django.views import View
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt,csrf_protect
from django.shortcuts import render, redirect, HttpResponse



@method_decorator(csrf_exempt,name='dispatch')
class Csrf_test(View):

# @method_decorator(csrf_protect)
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def get(self, request):
return render(request,'csrf_test.html')


def post(self, request):
return HttpResponse('我不需要校驗CSRF')
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM