因此,我试图连接我的angular2 app
托管在localhost:4200
上的django api托管在localhost:8000
,我已经有一个angular 1,6应用托管在本地主机:800管理登录和所有其他东西,
因此,在我的angular2应用程序中,我收到了存储在cookies中的令牌,我正试图使用它在头文件中将get请求发送到django api。你知道吗
ps:我已经检查了我的DjangoAPI,它目前允许访问所有服务器,没有例外。你知道吗
fetchUser(){
console.log("Here");
let headers = new Headers({'Accept': 'application/json','X-CSRFToken': this.token});
this.http.get( 'http://localhost:8000/api/orgs', {headers: headers}).subscribe(
(response: Response) => {
const testResponse = response.json();
this.outerLinks.data = testResponse;
this.data =testResponse;
this.dataChange.next(this.data);
}
);
}
所以我收到这个error
:
XMLHttpRequest cannot load localhost:8000/api/orgs. Response for preflight is invalid (redirect)
您可以尝试允许控制允许原点:* 如果你用Chrome试试这个 https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
修改您的设置.py通过添加以下代码:
相关问题 更多 >
编程相关推荐