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)