以HTML显示Python输出 [英] Display Python output in HTML
问题描述
最简单的显示Python ystockquote的方法是什么( http://goldb.org/ystockquote.html)HTML中的模块输出?我正在创建一个HTML仪表板,该仪表板将在我的计算机上本地运行,并希望将库存输出结果插入到指定的HTML占位符中.我希望因为它是本地的,所以可以避免许多CGI和服务器要求.
What is the simplest way to display the Python ystockquote (http://goldb.org/ystockquote.html) module output in HTML? I am creating an HTML dashboard which will be run locally on my computer and want to insert the stock output results into the designated HTML placeholders. I am hoping that because it is local I can avoid many CGI and server requirements.
推荐答案
我将使用模板系统(请参见 Python Wiki文章).如果您没有任何特别的喜好,jinja是一个不错的选择.这样一来,您就可以编写扩展了变量,控制流等内容的HTML,从而大大简化了自动生成HTML的过程.
I would use a templating system (see the Python wiki article). jinja is a good choice if you don't have any particular preferences. This would allow you to write HTML augmented with expansion of variables, control flow, etc. which greatly simplifies producing HTML automatically.
您可以简单地将渲染的HTML写入文件并在浏览器中打开它,这将避免您需要网络服务器(尽管在包含HTML文档的目录中运行python -m SimpleHTTPServer
会使它们在http://localhost:8000
下可用)
You can simply write the rendered HTML to a file and open it in a browser, which should prevent you from needing a webserver (though running python -m SimpleHTTPServer
in the directory containing the HTML docs will make them available under http://localhost:8000
)
这篇关于以HTML显示Python输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!