python - 如何结合 javascript/react 前端和 python 后端?

标签 python reactjs frontend backend

我不太确定我的问题是否重复,但我无法找到对我有帮助的东西。
设置 我已经构建了一个包含几个服务的前端网页,例如显示一些关于我的系统的时间序列和其他信息。该网站是使用 react 框架构建的,因此一般使用 javascript。现在我想做一些关于时间序列的计算,例如计算我的传感器数据的相似性和其他特征。为此,我正在使用 python,它为我提供了许多我使用了很长时间并且易于使用的库。 我在找什么:我正在寻找一种非常简单的方法来从 react GUI 调用我的 backend-timeseries-analysis-python 脚本,并传递一些变量,例如系列的长度。此外,我想处理返回的值并保护归一化所需的当前值(如最大值、最小值)以进行进一步计算。

因此,该过程如下所示:

1) Type value in react frontend input box
2) react/javascript calls pythonscript/ initialize a class and passes variables to class
3) python calculates similarity of sensor data 
4) python returns similarity values to frontend and saves classes for later call
5) react displays returned values
6) react/javascript calls pythonscript
7) python compares latest data to past data and refreshs treshholds(like max, min)
8) python calculates similarity of sensor data 
9) continue.. 

谢谢你的帮助!

System set up

最佳答案

您可以在 REST API 上公开您的 Python 脚本,该 API 将由您的 React 前端调用。此 API 将建立数据库连接,并将响应发送到您的前端。

Flask (对于小项目非常简单)甚至 Django构建 Python API。

关于python - 如何结合 javascript/react 前端和 python 后端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60528792/

相关文章:

python - 如何将 Python 线程代码转换为多处理代码?

python - 判断两行中第一行是否为标题

Python 正则表达式 Lookahead 多个条件

python - 我如何在Python中发送电子邮件?

ios - XCode 错误 'YogaKit.modulemap' 未找到

javascript - 失败的 Prop 类型 : Invalid prop `style` of type `number` supplied to `Styled(Container)` , 预期 `object`

javascript - React 在 return 中调用函数来插入组件

javascript - 如何根据身份验证在我的 Reactjs 应用程序中添加 header

javascript - 输入框和 css 改变颜色

javascript - 确定各种标签的默认浏览器样式