【发布时间】:2019-12-17 22:04:25
【问题描述】:
我正在开发一个基于 react-native 的移动应用程序,并在后台使用 python 进行一些操作。我想做这两个事务并通过 Django rest api 连接到数据库。但我收到连接错误。 我用过其他的rest-api并尝试过。我还在邮递员上尝试了其余的 api,它运行得很顺利。 我尝试了一切,但找不到解决方案。
本地休息网址:http://localhost:8000/api/venues/
并获取代码:
componentDidMount() {
return fetch('http://localhost:8000/api/venues/?format=json')
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
this.setState({
isLoading: false,
dataSource: responseJson,
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
【问题讨论】:
-
我认为您需要允许服务器端的 cors 看看here
-
我试过了,在你提到之后,但它没有奏效。我将我的 Django 设置添加为 img。
标签: django rest react-native django-rest-framework connection