【问题标题】:How to update data on a react app from python?如何从 python 更新反应应用程序上的数据?
【发布时间】:2020-06-20 23:35:06
【问题描述】:

我有这个基本的应用程序,它可以从 Json 文件中生成表单:

import React, { Component } from "react";
import { render } from "react-dom";

import Form from "react-jsonschema-form";

const schema = {
  "title": "A registration form",
  "description": "A simple form example.",
  "type": "object",
  "required": [
    "firstName",
    "lastName"
  ],
  "properties": {
    "firstName": {
      "type": "string",
      "title": "First name",
      "default": ""
    },
    "telephone": {
      "type": "string",
      "title": "Telephone",
      "minLength": 10
    }
  }
}

const log = type => console.log.bind(console, type);

render(
  <Form
    schema={schema}
    autocomplete="on"
    onChange={log("changed")}
    onSubmit={log("submitted")}
    onError={log("errors")}
  />,
  document.getElementById("root")
);

现在,我需要的是能够通过更改 Json 文件/内容来随意更改表单:

const schema = {
  "title": "A registration form",
  "description": "A simple form example.",
  "type": "object",
  "required": [
    "firstName",
    "lastName"
  ],
  "properties": {
    "firstName": {
      "type": "string",
      "title": "First name",
      "default": ""
    },
    "telephone": {
      "type": "string",
      "title": "Telephone",
      "minLength": 10
    }
  }
}

我从 Python 上的另一个应用程序获得了该信息,我当时的想法是发出 Post 请求以响应发送此信息。但是现在我看到 react 只是一个前端框架,所以我不确定是否可以在那里接收请求或者是否只能发出请求,这将是我正在考虑的架构的一个重大变化

【问题讨论】:

    标签: javascript python reactjs


    【解决方案1】:

    您可以使用 React 向 Python 服务器发送 GET 请求,以使用任何客户端获取方法获取您需要的数据,并根据这些数据呈现结果。这需要 Python 服务器来托管要使用的端点。

    【讨论】:

      猜你喜欢
      • 2020-03-05
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 2011-10-19
      • 2016-01-15
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      相关资源
      最近更新 更多