I am trying to use Vue.js to create some POST methods for my REST Api created using the Django Rest Framework. The problem is that I am getting CSRF Failed: CSRF token missing or incorrect. error CSRF Failed: CSRF token missing or incorrect. when sending. But I see a csrf cookie, and it is added to the headers.
Here are my settings:
REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ( 'rest_framework.permissions.IsAuthenticated', 'rest_framework.permissions.DjangoModelPermissions' ), 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework.authentication.SessionAuthentication', 'rest_framework.authentication.BasicAuthentication' ) }
Here is my Vue.js configuration:
var csrftoken = Cookies.get('csrftoken'); Vue.http.headers.common['HTTP_X_CSRFTOKEN'] = csrftoken;
And here is the relevant part of the headers that were sent:
Cookie:djdt=hide; tabstyle=raw-tab; sessionid=1gl533mrneudxw3l9l2vg0ja1yowwmeo; csrftoken=dN85bhztB1oVRov87BsUrWTM29Ff9sjn Host:127.0.0.1:8000 HTTP_X_CSRFTOKEN:dN85bhztB1oVRov87BsUrWTM29Ff9sjn Origin:http://127.0.0.1:8000 Referer:http://127.0.0.1:8000/agencies/6/add-profiles/
As you can see, Cookie.csrf and the HTTP_X_CSRFTOKEN header match
I'm really at a standstill. Any suggestions?
Dave merwin
source share