来自 Python 的 HTML 片段
我对 Python 和 CGI 很陌生,所以这可能是微不足道的。但我希望 Python 在访问者加载页面时生成 HTML 块。
<html>
<body>
<!-- Beautiful website with great content -->
<!-- Suddenly... -->
<h1> Here's Some Python Output </h1>
<!-- RUN PYTHON SCRIPT, display output -->
</body>
</html>
使用Python脚本,为了简单起见,看起来像这样:
#!/usr/bin/python
print "Content-type: text/html"
print
print "<p>Hello world!</p>"
我能找到的大多数资源都演示了如何使用Python脚本生成整个网页。您可以在页面中间调用 Python 脚本来生成 HTML 片段吗?
I'm new to Python and CGI, so this may be trivial. But I'd like Python to produce a block of HTML whenever a visitor loads a page.
<html>
<body>
<!-- Beautiful website with great content -->
<!-- Suddenly... -->
<h1> Here's Some Python Output </h1>
<!-- RUN PYTHON SCRIPT, display output -->
</body>
</html>
Using a Python script that, for simplicity, looks something like this:
#!/usr/bin/python
print "Content-type: text/html"
print
print "<p>Hello world!</p>"
Most resources I was able to find demonstrate how to produce an ENTIRE webpage using a Python script. Can you invoke a Python script mid-page to produce JUST an HTML snippet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 AJAX 客户端或模板服务器端。
模板将允许您保持页面的大部分静态,但使用服务器端脚本语言(如 Python)来填充动态位。 Stackoverflow 上有很多关于 Python 模板系统的好文章。 这是一个
AJAX将允许您更新页面之后最初加载来自服务器的结果。
Use AJAX client-side, or templates server side.
A template will allow you to keep most of your page static, but use a server-side scripting language (like Python) to fill in the dynamic bits. There are lots of good posts on Python template systems on Stackoverflow. Here's one
AJAX will allow you to update a page after it initially loads with results from a server.