django CSRF Disable

Sample class for CSRF disable

from rest_framework.authentication import SessionAuthentication, BasicAuthentication

class CsrfExemptSessionAuthentication(SessionAuthentication):

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

In view add

class MyTableDetailApiView(generics.RetrieveUpdateDestroyAPIView):
    queryset = MyTable.objects.all()
    serializer_class = MyTableSerializer
    authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication)

Cuauhtemoc Over 5 years ago