[英]Using ReactJS and python Flask. General Approach
I am working on project, that I started with Python and Flask, as at the begginning it was quite small - the jinja templates commonly used by Flask was sufficient, but as I wanted more and more - I decided to give a try to ReactJS.我正在研究项目,我从 Python 和 Flask 开始,因为在开始时它很小 - Flask 常用的 jinja 模板就足够了,但是随着我想要的越来越多 - 我决定尝试 ReactJS。
It works great for variety of things, and there is bigger control of whole frontend, and generally I like it, but Let's assume that I want to use react for X component, and in the same X component i'd like to use jinja templates - to populate it with data from Flask backend.它适用于各种事情,并且对整个前端有更大的控制,通常我喜欢它,但是假设我想对 X 组件使用 react,并且在同一个 X 组件中我想使用 jinja 模板- 用来自 Flask 后端的数据填充它。 This is the first question - 1) How should be this achieved?
这是第一个问题 - 1)这应该如何实现? React is preparing javascript file, so the tempalte can't be rendered.
React 正在准备 javascript 文件,因此无法呈现模板。 Should I create some endpoint, and GET data needed to populate with jquery request?
我应该创建一些端点,并获取需要用 jquery 请求填充的数据吗?
The second question is - the routing.第二个问题是——路由。 I define some endpoints in flask - but in react components I need to 'hardcode' it.
我在烧瓶中定义了一些端点 - 但在反应组件中我需要对其进行“硬编码”。 Is there some solution to not have it hardcoded in 2 places?
是否有一些解决方案可以不将其硬编码在 2 个地方?
The third question is - how do you work with that?第三个问题是 - 你如何处理它? Maybe good point is to combine React for some components, and use tempaltes for other things?
也许好的一点是将 React 用于某些组件,而将模板用于其他事物?
Summarizing question:总结问题:
I am very interested in your opinions about this two frameworks working together :)我对你对这两个框架协同工作的看法很感兴趣:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.