jquery - Cannot get CORS to work with contenType - Django Rest Framework -
i have been wasting whole day on stupid little issue!
i'm using django-rest-framework
api , backbone.js in front end.
i cannot request server when adding option contenttype
.
here simple example of i'm trying do:
$.ajax url:"http://127.0.0.1:8080/foo/" type:"post" data: '{"e":"e"}' contenttype: "application/json"
the options fails , post never sent.
the options request headers:
access-control-request-headers:accept, origin, content-type access-control-request-method:post origin:http://localhost:8000
now don't know why options fail. i'm using corsheaders app django, , settings follows:
cors_origin_allow_all = true cors_allow_headers = ( 'x-requested-with', 'content-type', 'accept', 'origin', 'authorization' )
cors_origin_allow_all = true
is enough if have following setup correctly
installed_apps = ( * 'corsheaders', ) middleware_classes = ( * 'corsheaders.middleware.corsmiddleware', 'django.middleware.common.commonmiddleware', )
Comments
Post a Comment