【发布时间】:2021-09-04 08:21:15
【问题描述】:
问题: 我正在尝试处理用户在 React Frontend 中输入的表单中的数据。我想对变量进行一些计算,目前只想将其打印出来,最终我想将信息返回给 React 应用程序,但我无法让这个简单的步骤工作。
我的尝试: 这是我正在使用的表单的 sn-p:
<form className="patient-form" method="post">
<input type="text" name="variable" />
<input type="submit" />
这是我要在其中使用变量的 Python 后端:
from flask import Flask,request
app = Flask(__name__)
@app.route('/',methods=['POST'])
def getVariable():
variable = request.json["variable"]
return {"variable": 'Backend variable' + variable}
我还在 package.json 中使用代理,以便 React 和 Flask 同时工作。
当我从我得到的表格中输入信息时:
Cannot Post /. --> This is on localhost:3001
在烧瓶后端我得到:
The method is not allowed for the requested URL.
所以这似乎我使用了错误的路线,我应该使用哪条路线来实现这一点?
如果这很简单,我深表歉意,因为您可以说我是 React 和 Flask 的新手。
我发现了这个帖子:How to send data from React to Flask then back to react and show output on DOM
我仍然无法从前端表单将数据 POST 到烧瓶后端,我是否遗漏了一些简单的东西?
【问题讨论】: