javascript 我们可以在 react 中使用 python 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53484453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:13:16  来源:igfitidea点击:

Can we use python with react?

javascriptpythonnode.jsreactjs

提问by Beebas Rijal

I have seen many people are using Nodejswith reactjsbut I liked pythonand reactso much that I wanted to know if I could pythonwith react. If so could you please give me some links for learning that please

我看到很多人在使用Nodejsreactjs,但我喜欢python并且反应如此之多以至于我想知道我是否可以使用reactpython。如果可以,请给我一些学习链接

回答by Morgan

I have experience building web applications using React and Python Flask together, so perhaps I can help.

我有使用 React 和 Python Flask 构建 Web 应用程序的经验,所以也许我可以提供帮助。

I do not know of a way to directly use Python on client-side web applications, but there are certainly plenty of ways to use Python on the backend. The most popular Python web frameworks are Flaskand Django.

我不知道在客户端 Web 应用程序上直接使用 Python 的方法,但肯定有很多方法可以在后端使用 Python。最流行的 Python Web 框架是FlaskDjango

If so could you please give me some links for learning that please

如果可以,请给我一些学习链接

YouTuber Corey Schafer has a great YouTube tutorial series on Flask, which I would wholeheartedly recommend.

YouTuber Corey Schafer 有一个很棒的关于 Flask 的 YouTube 教程系列,我会全力推荐。

Once you get more comfortable with web development in Python, I think the website https://realpython.com/has great tutorials for both specific questions (e.g. Token-Based Authentication in Flask) and more general tutorials.

一旦您对 Python 中的 Web 开发更加熟悉,我认为网站https://realpython.com/为特定问题(例如Flask 中的基于令牌的身份验证)和更一般的教程提供了很好的教程。

If you go with Django, it has a great ORM built in for working with databases.

如果你使用 Django,它内置了一个很好的 ORM 来处理数据库。

If you go with Flask, which is definitely more beginner friendly IMO, I would recommend Peewee ORMfor working with relational databases unless you have more complicated use-cases, in which case SQLAlchemyis the de-facto standard.

如果你使用 Flask,这绝对是对初学者更友好的 IMO,我会推荐Peewee ORM来处理关系数据库,除非你有更复杂的用例,在这种情况下SQLAlchemy是事实上的标准。

Good luck learning!

祝学习顺利!



Update

更新

I just came across this cool Python library called Transcryptthat transpiles Python code into JavaScript, so it turns out you can write client-side code for the web in Python. Their website has some cool tutorials.

我只是碰到叫这个凉爽的Python库来Transcrypt是transpiles Python代码为JavaScript,所以事实证明,你可以写客户端代码在Python中的网络。他们的网站有一些很酷的教程

回答by Fawzi

Yes. React is mostly agnostic of what's going on at the server-level. ie it does not care what backend you use.

是的。React 基本上不知道服务器级别发生的事情。即它不在乎你使用什么后端。

Check this example : https://realpython.com/the-ultimate-flask-front-end/

检查这个例子:https: //realpython.com/the-ultimate-flask-front-end/

回答by jujule

React is backend-agnostic.

React 与后端无关。

React manages the UI, which possibly interacts with some HTTP APIs regardless in what language they're made of.

React 管理 UI,它可能与一些 HTTP API 交互,而不管它们是用什么语言制作的。

What's important is that your API use some standard like REST, jsonapior GraphQLso you can benefit a wide range of tools (documentation, tests...)

重要的是您的 API 使用了一些标准,如RESTjsonapiGraphQL,因此您可以受益于广泛的工具(文档、测试......)

That said, if you want to make "server-side-rendered" react web apps, like Next.jsdoes, or if you need WebSockets, you'll need NodeJS on the server-side too. Also, the ability to use the same code, tooling and ecosystem on the client and the server is useful for a developer.

也就是说,如果你想像Next.js那样制作“服务器端渲染”的ReactWeb 应用程序,或者如果你需要 WebSockets,你也需要在服务器端使用NodeJS。此外,在客户端和服务器上使用相同代码、工具和生态系统的能力对开发人员很有用。

回答by Chan Austin

https://plot.ly/python/

https://plot.ly/python/

I have been using this to build up react app with python. They have new libs 'dash' and dash component whose underlying is react.js.

我一直在使用它来构建带有 python 的 react 应用程序。他们有新的库“破折号”和破折号组件,其底层是 react.js。