json - 没有从烧瓶路由到 ReactJS 前端的响应
问题描述
我正在将表单数据从 ReactJS 前端传递到烧瓶后端以解决预测问题,并希望以 JSON 格式获得预测,但我无法从后端收到任何响应。
反应前端代码:
handleFormSubmit = (event) => {
fetch('http://127.0.0.1:5000/predict', {
method: 'POST',
body: JSON.stringify(this.state.patientData)
}).then(response => response.json())
.then(response => {
this.setState({
result: response.result
})
})
}
烧瓶后端代码:
@app.route('/predict', methods=['POST'])
def handleJSON():
data = request.get_json(force = True)
test_data = list(data.values())
test_data = pd.DataFrame([test_data])
# Column Transformer
ct_pkl = open('ct.pkl', 'rb')
ct = pickle.load(ct_pkl)
test_data = ct.transform(test_data)
# Logistic Regression Model
lr_pkl = open('lr.pkl', 'rb')
model = pickle.load(lr_pkl)
pred = model.predict(test_data)
response = jsonify({"statusCode": 200, 'result': pred[0]})
return response
解决方案
推荐阅读
- javascript - 量角器 CCS 选择器无法在隐藏的工具栏上找到元素
- db2 - 从 DB2 列获取子字符串
- highcharts - 为每个旭日形水平设置不同的工具提示格式化程序 - Highcharts
- angular - 是否可以在 Angular Material Design Angular 5 中为对话框设置不同的高度和宽度
- kubernetes - 通过水平扩展选择集群中节点的计算资源
- performance - 可能使用并发/异步/并行方法比较 2 个数据集
- r - 有没有办法在 Plotly(特别是 R)中隐藏跟踪名称?
- python - 使用 href 链接抓取网页
- express - Express.js/socket.io/knockout.js simpleGrid 更新通过 socket.io
- c# - 如何在 Autofac 中注册其构造函数采用 Func 参数的类型