django CSRF Disable

Posted Over 5 years ago. Visible to the public.

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
Last edit
Over 5 years ago
Cuauhtemoc
Posted by Cuauhtemoc to Python Django (2018-10-01 15:23)