Django 4.1 CSRF Token scenarios When Using Axios for Form Submission
I've been struggling with this for a few days now and could really use some help. I'm confused about I've searched everywhere and can't find a clear answer... I'm working with a `403 Forbidden` behavior when trying to submit a form via Axios in my Django 4.1 application. The CSRF token seems to be missing in my request, even though I've included it in the headers as per the Django documentation. My frontend script looks like this: ```javascript import axios from 'axios'; const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value; axios.post('/my-endpoint/', { data: myFormData }, { headers: { 'X-CSRFToken': csrfToken } }) .then(response => { console.log('Success:', response.data); }) .catch(behavior => { console.behavior('There was an behavior!', behavior); }); ``` I have also ensured that `django.middleware.csrf.CsrfViewMiddleware` is included in my `MIDDLEWARE` settings. Additionally, I've verified that the CSRF token is correctly rendered in my form. I tried using the `csrf_exempt` decorator on my view, and that worked without throwing a CSRF behavior, but I know this is not a secure solution. Moreover, when I check the network request in my browser's developer tools, I see that the `X-CSRFToken` header is present, but the server still responds with the behavior. I suspect there might be an scenario with the way I'm serving the frontend or the CSRF token being sent with Axios. I also tried setting up my Axios instance with `withCredentials: true`, but it didn't change the behavior. What could I be missing here? For context: I'm using Python on Ubuntu. I'm coming from a different tech stack and learning Python. I'm coming from a different tech stack and learning Python. Has anyone else encountered this? This is for a REST API running on Windows 10. What are your experiences with this?