从Python Dictionary生成HTML表

Err*_*ing 5 html python linux web2py web

我如何将字典转换为html表格

  {'Retry': ['30', '12', '12'] 'Station MAC': ['aabbccddeea', 'ffgghhiijj', 'kkllmmnnoo'] Download': ['70.', '99', '90'] }
Run Code Online (Sandbox Code Playgroud)

我试图实现的Html表格式是

Retry       MAC         Download
  30      aabbccddee        70
  12      ffgghhiijj        99
  12      kkllmmnnoo        90
Run Code Online (Sandbox Code Playgroud)

我已经为包含边框和所有内容的表编写了css,但数据未正确填充.我正在尝试使用web2py.但是发现难以编写逻辑以表格格式打印在字典之上.

谢谢 !

Ant*_*ony 5

您可以使用web2py TABLETR帮助程序使其更容易一些:

在控制器中:

def myfunc():
    d = {'Retry': ['30', '12', '12'],
         'Station MAC': ['aabbccddeea', 'ffgghhiijj', 'kkllmmnnoo'],
         'Download': ['70.', '99', '90']}
    colnames = ['Retry', 'Station MAC', 'Download']
    rows = zip(*[d[c] for c in colnames])
    return dict(rows=rows, colnames=colnames)
Run Code Online (Sandbox Code Playgroud)

在视图中:

{{=TABLE(THEAD(TR([TH(c) for c in colnames])),
         [TR(row) for row in rows]))}}
Run Code Online (Sandbox Code Playgroud)