django-cors-headers CORS_ORIGIN_WHITELIST元组与字符串问题 [英] django-cors-headers CORS_ORIGIN_WHITELIST tuple vs string issue

查看:1451
本文介绍了django-cors-headers CORS_ORIGIN_WHITELIST元组与字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为项目使用django-cors-headers.

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

当我将CORS_ORIGIN_WHITELIST设置为字符串时,它会正常显示.但是,当我将其用作元组时,它不起作用.知道为什么吗?在文档中找不到关于使用元组或字符串之间的区别的任何具体信息.

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.

要加载JSON,我正在使用jQuery $ .getJSON()

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" );
});

推荐答案

我遇到了同样的问题.我相信这个问题与字符串编码有关.如果您将白名单更改为以下列表,那么它应该对您有用:

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.

这篇关于django-cors-headers CORS_ORIGIN_WHITELIST元组与字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆