【发布时间】:2020-12-04 04:25:24
【问题描述】:
我是 Django 和 React Native 的新手。 我尝试制作一个使用 axios 将数据发送到 django 后端的应用程序,但出现网络错误。 我尝试在 192.168.xxx 中更改我的 localhost ip,但没有任何改变。
所以我不明白为什么我没有任何请求。
这是我的代码:
姜戈:
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = (
'http://localhost:8081',
'http://localhost:19006',
'http://localhost:19002',
'http://192.168.101.6:19000',
)
Axios:
import axios from "axios";
export default axios.create({
baseURL: "http://192.168.101.6:8080/api",
headers: {
"Content-type": "application/json"
}
});
请求:
import http from "../http-common";
const getAll = () => {
return http.get("/tutorials");
};
const get = id => {
return http.get(`/tutorials/${id}`);
};
const create = data => {
return http.post("/tutorials", data);
};
【问题讨论】:
-
你添加
'corsheaders.middleware.CorsMiddleware'到你的DjangoMIDDLEWARE了吗?
标签: django react-native django-rest-framework