python 从python代码获取html输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1953649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 23:25:46  来源:igfitidea点击:

Get html output from python code

pythonhtml

提问by yart

I have dictionary and would like to produce html page where will be drawn simple html table with keys and values. How it can be done from python code?

我有字典,并想生成 html 页面,其中将绘制带有键和值的简单 html 表。如何从 python 代码中完成?

回答by rui

output = "<html><body><table>"
for key in your_dict:
  output += "<tr><td>%s</td><td>%s</td></tr>" % (key, your_dict[key])
output += "</table></body></html>
print output

回答by jbochi

You can use a template engine like Jinja. A list of engines for templating is available here.

您可以使用像Jinja这样的模板引擎。模板引擎列表可在此处获得

回答by sateesh

You may also consider using Makotemplate library.

您也可以考虑使用Mako模板库。

回答by luc

You maybe interested by markup see http://markup.sourceforge.net/

您可能对标记感兴趣,请参阅http://markup.sourceforge.net/

回答by chauncey

Along with the numerous template engines, you might consider using Python's built in Template.It will give you basic templating functionality without needing to learn (or choose) a template library.

除了众多的模板引擎之外,您还可以考虑使用 Python 的内置模板。它将为您提供基本的模板功能,而无需学习(或选择)模板库。