现在你可以在HTML页面里内嵌Python代码,就像PHP一样。
需要安装吗?开玩笑!你不需要安装任何东西。直接引用下面的css和js就OK了。
<head>
<!-- PyScript CSS -->
<link rel="stylesheet" href="https://pyscript.net/releases/2024.1.3/core.css">
<!-- This script tag bootstraps PyScript -->
<script type="module" src="https://pyscript.net/releases/2024.1.3/core.js"></script>
</head>
shell> cd /home/yourname/
shell> python3 -m http.server 80
<!doctype html>
<html>
<head>
<!-- Recommended meta tags -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- PyScript CSS -->
<link rel="stylesheet" href="https://pyscript.net/releases/2024.1.3/core.css">
<!-- This script tag bootstraps PyScript -->
<script type="module" src="https://pyscript.net/releases/2024.1.3/core.js"></script>
</head>
<body>
<h1> 这是一个测试页,在HTML页面里内嵌Python代码,就像PHP一样。</h1>
<h2>
<script type="py">
# 这里写Python代码
from pyscript import display
from datetime import datetime
now = datetime.now()
display(now.strftime("%m/%d/%Y, %H:%M:%S"))
display("-" * 55)
for i in range(20):
display(i)
</script>
</h2>
</body>
</html>
参考官网:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。