Mel*_*oun 22 html python generator
我正在为python寻找一个易于实现的html生成器.我找到了这个
http://www.decalage.info/python/html
Run Code Online (Sandbox Code Playgroud)
但是没有办法为表添加css元素(id,class).
谢谢
如果你想要编程生成而不是模板化,Karrigell的HTMLTags模块是一种可能性; 它可以包括例如class属性(在Python中将是一个保留字)通过大写其初始化的技巧,即引用我刚给出的doc URL:
与Python关键字(类,类型)同名的属性必须大写:
Run Code Online (Sandbox Code Playgroud)print DIV('bar', Class="title") ==> <DIV class="title">bar</DIV>
Dominate是一个HTML生成库,可让您轻松创建标记.在dominate中,python保留字以下划线为前缀,因此它看起来像这样:
from dominate.tags import *
t = div(table(_id="the_table"), _class="tbl")
print(t)
<div class="tbl">
<table id="the_table"></table>
</div>
Run Code Online (Sandbox Code Playgroud)
免责声明:我是支配者的作者
这是我编写的一个超简单的HTML生成器.我使用它构建时生成html.如果有人生成html页面运行时,那么有更好的选项可用
链接在这里
http://pypi.python.org/pypi/sphc
还有一个简单的例子
>> import sphw
>> tf = sphw.TagFactory()
>>> div = tf.DIV("Some Text here.", Class='content', id='foo')
>>> print(div)
<DIV Class="content", id="foo">Some Text here.</DIV>
Run Code Online (Sandbox Code Playgroud)