django drf关闭接口csrf验证

from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated


class CsrfExemptSessionAuthentication(SessionAuthentication):
    """
    关闭csrf验证
    """

    def enforce_csrf(self, request):
        return  # To not perform the csrf check previously happening


# 认证
permission_classes = (IsAuthenticated,)
authentication_classes = (BasicAuthentication, CsrfExemptSessionAuthentication)

  

posted @ 2021-12-21 17:51  Maltone  阅读(305)  评论(0)    收藏  举报