我使用yattag生成HTML:
doc, tag, text = Doc().tagtext()
with tag("p"):
text("My paragraph.")虽然它运行得很好,但当我查看HTML源代码时,它就会出现在一行上。是否有某种开关或其他技巧可以使yattag创建更易读的源?
发布于 2015-05-16 15:48:30
使用indent函数。
from yattag import Doc, indent
doc, tag, text = Doc().tagtext()
with tag("p"):
text("My paragraph.")
print(indent(doc.getvalue())) # will indent the tags but not the text directly contained between <tag> and </tag>
print(indent(doc.getvalue(), indent_text = True)) # will also indent the text directly contained between <tag> and </tag>https://stackoverflow.com/questions/30248499
复制相似问题