django-cors-headers CORS_ORIGIN_WHITELIST tuple vs string issue

為{幸葍}努か 提交于 2020-01-16 16:45:13

问题


I'm trying to use django-cors-headers for my project.

It appears when I set CORS_ORIGIN_WHITELIST as a string it works fine. But when I use it as a tuple it doesn't work. Any idea why? I can't find anything specific in the documentation about the difference between using a tuple or string.

To load the JSON I'm using jQuery $.getJSON()

$.getJSON( "http://127.0.0.1:8000/accounts/api_r/44234138/?format=json", function( data ) {
  var items = [];
  $.each( data, function( key, val ) {
    items.push( "<li id='" + key + "'>" + val + "</li>" );
  });

  $( "<ul/>", {
    "class": "my-new-list",
    html: items.join( "" )
  }).appendTo( "#foo" );
});


回答1:


I was having this same problem. I believe the issue has to do with string encoding. If you change your whitelist to the following it should work for you:

CORS_ORIGIN_WHITELIST = (
    u'http://localhost:8888',
    u'http://127.0.0.1:8000',
)

Unfortunately I don't have a "why" for you, but at least this should get you going.



来源:https://stackoverflow.com/questions/50880593/django-cors-headers-cors-origin-whitelist-tuple-vs-string-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!