使用纯数据结构从Python呈现HTML,灵感来自Clojure的Hiccup
piccup的Python项目详细描述
皮卡普
[实验性]
使用纯数据结构从Python呈现HTML,灵感来自Clojure的Hiccup。在
安装
pip install piccup
使用
piccup允许您使用纯Python数据结构编写HTML。在
^{pr2}$每个HTML节点都是使用[element, attributes, contents]
三元组定义的。element
字符串是必需的,attributes
dict和{
>>>p.html(['a',{'href':'http://example.com'},'Click Me'])'<a href="http://example.com">Click Me</a>'
嵌套的HTML节点被传递给contents
。在
>>>p.html(['ul',[['li','first'],['li','second'],['li','third']]])'<ul><li>first</li><li>second</li><li>third</li></ul>'
piccup使用简单的数据结构,因此您可以编写普通的Python代码,而不是使用外来的模板语言。在
>>>p.html(['ul',[['li',{'class':'link-item'},['a',{'href':'http://example.com/{}'.format(e)},e]]forein['item1','item2','item3']]])'<ul><li class="link-item"><a href="http://example.com/item1">item1</a></li><li class="link-item"><a href="http://example.com/item2">item2</a></li><li class="link-item"><a href="http://example.com/item3">item3</a></li></ul>'
- 项目
标签: