S.No | 命令和说明 |
1. |
serialize
它以字符串形式返回输出内容。
|
2. |
generate
它将输出内容作为迭代器返回。
|
3. |
write
它将输出内容转储到文件对象中。
|
S.No | 命令和说明 |
1. |
encoding
它通知如何对输出内容进行编码
|
2. |
fragment
它是一个布尔值,告诉 XML prolog 或 Doctype
|
3. |
输出
这种类型的序列化用于渲染内容
|
<!DOCTYPE html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns:py = "http://purl.org/kid/ns#"> <head> <title>${title}</title> <link rel = "stylesheet" href = "style.css" /> </head> <body> <p>${message}</p> </body> </html> The next step after saving the file is to process the template via the Kid engine. import kid params = {'title': 'Hello world!!', 'message': 'CherryPy.'} t = kid.Template('helloworld.kid', **params) print t.serialize(output='html')
<p py:if = "...">...</p>
<tag py:if = "expression">...</tag>
<tag py:for = "expression">...</tag>
<!DOCTYPE html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>${title}</title> <link rel = "stylesheet" href = "style.css" /> </head> <body> <table> <caption>A few songs</caption> <tr> <th>Artist</th> <th>Album</th> <th>Title</th> </tr> <tr py:for = "info in infos"> <td>${info['artist']}</td> <td>${info['album']}</td> <td>${info['song']}</td> </tr> </table> </body> </html> import kid params = discography.retrieve_songs() t = kid.Template('songs.kid', **params) print t.serialize(output='html')