python - 在 HTML 文件中导入 Python 代码

标签 python html python-2.7 python-3.x

如上所述here ,我可以使用 <% 在 .html 文件中导入 Python 代码和%>标签。为了尝试一下,我在记事本中编写了以下代码并将其保存为名为 test.html 的文件:

<html>
<title>
</title>
<body>
<%print ("Hello")%>
</body>

双击 test.html 后,Chrome 将打开,顶部显示以下行:

<%print ("Heloo")%>

我必须做什么才能在输出中显示“Hello”?

注:“print”是一个例子,有哪些方式可以在html文件中导入并运行python代码?

最佳答案

该页面与 Karrigell 相关,这是一个 Python Web 框架,如果您使用像 web.py 这样的 Python Web 框架,则只能有 Python 和 HTML 文件(网页)。 , Pylons , Django ,和others .

浏览器只能执行JavaScript代码,其他编程语言必须使用特殊组件才能由浏览器执行。

关于python - 在 HTML 文件中导入 Python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25709110/

相关文章:

python - Python 中十六进制数的二进制补码

python - Fipy 中的 Dirac delta 源术语

python - 如何通过 python 中的 webapp2 处理程序修改 ndb 模型的属性

python - 将 numpy 数组转换为另一个数组

python - BeautifulSoup:从子节点中提取值(value)

html - Bootstrap 2 响应图像

javascript - 显示/隐藏表单元素的问题

python 类型错误: dl() takes exactly 4 arguments (3 given)

python - TPOT P@K 定制记分器

html - 链接 rel ="canonical": Should different user guide versions use the same canonical url?