问题
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