简体   繁体   English

是否有一种安全的方法可以将 React.js 与 Python Flask 后端一起用于多用户、受密码保护的站点

[英]Is there a secure way to use React.js with a Python Flask backend for a multi-user, password protected site

I'm familiar with Flask for building simple webapps and using jinja2 as a template engine.我熟悉 Flask 用于构建简单的 web 应用程序并使用 jinja2 作为模板引擎。 However, I'd like to try out React.js as a front-end.但是,我想尝试使用 React.js 作为前端。

The examples I've seen that use React.js with a Python backend essentially use it as an API server to call the json needed to include in the React views.我所看到的使用带有 Python 后端的 React.js 的示例本质上是将其用作 API 服务器来调用需要包含在 React 视图中的 json。 However, how does this work with authentication models and libraries for Flask?但是,这如何与 Flask 的身份验证模型和库配合使用? Can you mix-and-match jinja2 and React.js within the same template, to get access to the session data?你能在同一个模板中混合搭配 jinja2 和 React.js 来访问会话数据吗?

Any pointers or experience to help get started would be appreciated.任何帮助入门的指针或经验将不胜感激。

It is possible to use React.js within the Jinja2 template system. 可以在Jinja2模板系统中使用React.js。 This is the solution, placing the React components within an authorised user if loop, using a library like Flask-Login. 这是解决方案,使用Flask-Login之类的库将React组件放置在经过授权的用户if循环中。

Here's a further example I found of someone working this through: Flask and Reactjs throw JSX Transform error . 这是我发现有人通过它完成工作的另一个示例: Flask和Reactjs抛出JSX Transform error

For those of you who are thinking to use react and flask to build an app, please read this article below.对于那些正在考虑使用 react 和 flask 来构建应用程序的人,请阅读下面的这篇文章。 I used this concept for my project:我在我的项目中使用了这个概念:

https://towardsdatascience.com/build-deploy-a-react-flask-app-47a89a5d17d9 https://towardsdatascience.com/build-deploy-a-react-flask-app-47a89a5d17d9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM