微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Pyramid 后端和 React JS 前端返回时出现问题

如何解决使用 Pyramid 后端和 React JS 前端返回时出现问题

我正在开发带有 Pyramid 后端和 JS 前端的 RESTful API。 前端可以向后端发送JSON,后端可以接收。

我用 JSONplaceholder 测试了前端,它工作正常,可以发送和接收。 后端似乎可以发送,但前端会收到:

<!DOCTYPE html>
<html lang="en">
  <head>
    <Meta charset="utf-8" />
    <link rel="icon" href="/favicon.ico" />
    <Meta name="viewport" content="width=device-width,initial-scale=1" />
    <Meta name="theme-color" content="#000000" />
    <Meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="/logo192.png" />
    <!--
      manifest.json provides Metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="/manifest.json" />
    <!--
      Notice the use of  in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico","/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser,you will see an empty page.

      You can add webfonts,Meta tags,or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development,run `npm start` or `yarn start`.
      To create a production bundle,use `npm run build` or `yarn build`.
    -->
  <script src="/static/js/bundle.js"></script><script src="/static/js/vendors~main.chunk.js"></script><script src="/static/js/main.chunk.js"></script></body>
</html>

这是后端代码

@view_config(route_name="route",renderer="json",request_method='POST')
def chatbot(req_received):
    #We get the message from the frontend : client's message
    message = req_received.json_body["message"]
    return {"response":"received"}

if __name__ == '__main__':

    with Configurator() as config:
        config.add_route('route','/')
        config.scan()
        app = config.make_wsgi_app()
    #Host / Port / Application
    server = make_server('127.0.0.1',3000,app)    
    print("RUNNING ...")
    server.serve_forever()

这是后端发送时从前端收到的错误

错误:网络错误
在 createError (createError.js:16)
在 XMLHttpRequest.handleError (xhr.js:84)

先谢谢你:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。