Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 反应本机+;Django DRF POST上的网络错误_Python_Reactjs_Django_React Native_Django Rest Framework - Fatal编程技术网

Python 反应本机+;Django DRF POST上的网络错误

Python 反应本机+;Django DRF POST上的网络错误,python,reactjs,django,react-native,django-rest-framework,Python,Reactjs,Django,React Native,Django Rest Framework,我正在开发一个React本地应用程序。作为后端,我使用DJango DRF。我正试图提出在后端创建新元素的POST请求,这是我在React中的代码: **API.JS** const routes = { accounts: { get: () => requestHelper({ method: "get", url: "accounts/", }), post: (dat

我正在开发一个React本地应用程序。作为后端,我使用DJango DRF。我正试图提出在后端创建新元素的POST请求,这是我在React中的代码:

**API.JS**
const routes = {
  accounts: {
    get: () =>
      requestHelper({
        method: "get",
        url: "accounts/",
      }),
    post: (data) =>
      requestHelper({
        data,
        method: "post",
        url: "accounts/",
      }),
  },
};

**API CALL**
const formData = new FormData();

const image = {
  uri: data.image,
  name: data.timestamp + ".jpg",
  type: "image/jpeg",
};

_.map(data, (item, name) => {
   formData.append(name, item);
});
    
formData.append("image", image);

await api.accounts
    .post(formData)
    .then((res) => {
      console.log(res, "OK");
    })
    .catch((err) => {
      console.log(err);
    });
};
Te请求正在到达后端,并且正在数据库(包括映像)上创建新帐户。问题是,尽管Django返回200_OK,但api调用将转到catch语句,并且控制台上出现此错误:

网络错误

堆栈跟踪:node_modules/axios/lib/core/createError.js:15:0 in node_modules/axios/lib/adapters/xhr.js:81:4英寸 DispatchXhreQuest
node_modules/event target shim/dist/event target shim.js:818:20 in EventTarget.prototype.dispatchEvent
node_modules/react native/Libraries/Network/XMLHttpRequest.js:575:10 在setReadyState中
中的node_modules/react native/Libraries/Network/XMLHttpRequest.js:389:6 __didCompleteResponse节点_modules/react native/Libraries/vendor/emitter/EventEmitter.js:189:10 在发射中
node_modules/react native/Libraries/BatchedBridge/MessageQueue.js:425:19 在调用函数中
node_modules/react native/Libraries/BatchedBridge/MessageQueue.js:112:6 在\uuuu保护$argument\u0中
node_modules/react native/Libraries/BatchedBridge/MessageQueue.js:373:10 在\uuuu防护装置中
node_modules/react native/Libraries/BatchedBridge/MessageQueue.js:111:4 在callFunctionReturnFlushedQueue[本机代码]中:空 callFunctionReturnFlushedQueue


我认为这不是图像问题,因为我已删除以进行测试,并且出现了相同的错误。

通常,当无法访问REST API服务器时,会出现
网络错误。您是否为Django服务器设置了正确的
baseURL
proxy
?Django服务器可能在
8000
上运行,而React默认在
3000
上运行


在服务器端看到请求的事实有点奇怪。这将表明用于处理成功响应的代码中可能存在错误/问题。您是否尝试删除该代码?是的,听起来可能很奇怪,只需删除
console.log(res,“OK”)看看会发生什么?

你好,普隆斯基。谢谢你的回答。baseURL配置正确,否则将无法创建帐户。请求很好地到达后端(Django控制台显示对请求的200响应)[04/Nov/2020 14:29:52]“POST/api/accounts/HTTP/1.1”200 12438不理解如果Django返回一个200_ok,为什么axios会输入catch语句您能显示代码来重现它吗?js端可能有错误,即使服务器响应为200,也会引发错误。当然可以,但我如何向您展示整个代码?请创建github repo,并提供运行应用程序的步骤