當我使用 Postman 發出 POST 請求時,我收到一個錯誤 Forbidden (CSRF cookie not set.)
class BooksView(View):
def post(self, request):
如果我使用csrf_exempt錯誤不會發生
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
@method_decorator(csrf_exempt, name='dispatch')
class BooksView(View):
def post(self, request):
但是,當我使用時根本不會發生此錯誤 django-rest-framework
from rest_framework.views import APIView
# /books
class BooksView(APIView):
def post(self, request):
什么是Django的REST的框架和APIView類關系在做csrf?
uj5u.com熱心網友回復:
django-rest-framework 中的所有視圖和視圖集都繼承自APIView,該類將自身包裹csrf_exempt 在as_view方法中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/378556.html
標籤:姜戈 Django 休息框架 django-views csrf django-csrf
