zl程序教程

您现在的位置是:首页 >  后端

当前栏目

不喜欢 JavaScript?PyScript 正在将 Python 带入您的浏览器(含demo源码)

PythonJavaScript源码浏览器 Demo 正在 喜欢
2023-09-11 14:18:32 时间

在这里插入图片描述
我对 PyScript 感到非常兴奋,它允许您编写 Python 代码并在浏览器上运行代码。

PyScript 由 Anaconda 的团队开发,其中包括 Peter Wang、Fabio Pliger 和 Philipp Rudiger。它是一个 JavaScript 框架,可让您将 Python 与 HTML 混合使用。它使更多的前端开发人员和创建者可以使用 Python 的强大功能。

在这篇文章中,我将通过提供示例来讨论使用 PyScript 的方式。

示例 1

这是 PyScript 最简单的例子。在本例中,我们将创建一个名为hello_world.html. 我们需要将此文件保存在我保存 PyScript JavaScript 和 CSS 文件的同一目录中。我们需要在浏览器中打开这个 hello_world.html 文件(推荐使用 Chrome)。

<html>
  <head>
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
  </head>
  <body> <py-script> print('Hello, World! This is our first PyScript') </py-script> </body>
</html>