In my cenario I am using a form in my react frontend (http://localhost:3000/submit) to post to my url http://localhost:8000/api/submit/
However, I have received this response:
"detail": "CSRF Failed: CSRF token missing or incorrect."
My class view is something like that:
from rest_framework.views import APIView
from rest_framework.parsers import MultiPartParser, FormParser
class Submit(APIView):
parser_classes = (MultiPartParser, FormParser)
def post(self, request, *args, **kwargs):
#custom post
I have two questions:
- How do I decorate dispatch() to exempt csrf?
- How can I provide CSRF to my frontend?
**
SOLUTION by Risadinha:
**
import cookie from "react-cookies";
...
<input
type="hidden"
value={cookie.load("csrftoken")}
name="csrfmiddlewaretoken"
/>
TokenAuthentication: django-rest-framework.org/api-guide/authentication/… --TokenAuthenticationmight be more appropriate for your client-server set up.