我正在尝试在具有行和列跨度的模板中呈现数据,但是所有内容都在一行中。
这是我尝试过的模板
data = [{'title':'overall','key':'shares','agg':'count','values':[ 1426118,748911,9128]},{'title':'overall','key':'shares','agg':'%Day Over Day','values':[5,2,4]}, {'title':'overall','key':'UU','agg':'Count','values':[45435,343322,34324]}, {'title':'overall','key':'UU','agg':'%Day Over Day','values':[3,2,1]}, {'title':'News','key':'shares','agg':'count','values':[ 1426118,748911,9128]}, {'title':'News','key':'shares','agg':'%Day Over Day','values':[5,2,4]}, {'title':'News','key':'UU','agg':'Count','values':[45435,343322,34324]}, {'title':'News','key':'UU','agg':'%Day Over Day','values':[3,2,1]} ]
share_template = """ <!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } th, td { padding: 5px; text-align: left; } </style> </head> <body> <table style="width:100%"> <tr> <tr> <th colspan="3">News/Buzz- Shares/UU</th> <th>Overall</th> <th>Whatsapp</th> <th>Facebook</th> </tr> {{#email_data1}} {{#title}} <td rowspan="4">{{{.}}}</td> {{#key}} <td rowspan="2">{{{.}}}</td> {{#agg}} <td>{{{.}}}</td> {{#values}} <td>{{{.}}}</td> {{/values}} {{/agg}} {{/key}} {{/title}} {{/email_data1}} </tr>""" print(pystache.render(share_template, email_data1 = data))
实际结果Actual Result
预期输出为Expected Result