django-cors-headers not work

后端 未结 13 1406
情深已故
情深已故 2020-12-29 04:10

django-cors-headers not work

INSTALLED_APPS = (
    \'django.contrib.admin\',
    \'django.contrib.auth\',
    \'django.contrib.contenttypes\',
    \'django.         


        
13条回答
  •  自闭症患者
    2020-12-29 04:28

    If you are testing this you need to ensure you include at least the Origin header in the request.

    E.g.:

    $ http GET http://127.0.0.1:8000/todos/ Origin:http://www.someorigin.com
    HTTP/1.0 200 OK
    Access-Control-Allow-Origin: *
    Allow: GET, POST, HEAD, OPTIONS
    Content-Type: application/json
    Date: Sat, 14 Nov 2015 04:42:38 GMT
    Server: WSGIServer/0.1 Python/2.7.10
    Vary: Accept, Cookie
    X-Frame-Options: SAMEORIGIN
    

    You will get more feedback with a preflight CORS request:

    $ http OPTIONS http://127.0.0.1:8000/todos/ Origin:http://www.someorigin.com
    HTTP/1.0 200 OK
    Access-Control-Allow-Headers: x-requested-with, content-type, accept, origin, authorization, x-csrftoken, user-agent, accept-encoding
    Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
    Access-Control-Allow-Origin: *
    Access-Control-Max-Age: 86400
    Allow: GET, POST, HEAD, OPTIONS
    Content-Type: application/json
    Date: Sat, 14 Nov 2015 04:45:37 GMT
    Server: WSGIServer/0.1 Python/2.7.10
    Vary: Accept, Cookie
    X-Frame-Options: SAMEORIGIN
    

提交回复
热议问题