web2py函数调用未按预期显示转换为html内容的数据帧

web2py函数调用未按预期显示转换为html内容的数据帧,html,pandas,web2py,Html,Pandas,Web2py,我是一个web2py初学者。我在web2py示例中尝试了hello3.py的一个简单变体。 hello3.py文件是 def hello3(): import pandas as pd import numpy as np xx = pd.DataFrame(np.zeros(4).reshape(2,2)) message=xx.to_html() return dict(message = message) hello3.html文件是 {{exte

我是一个web2py初学者。我在web2py示例中尝试了hello3.py的一个简单变体。 hello3.py文件是

def hello3():
    import pandas as pd
    import numpy as np
    xx = pd.DataFrame(np.zeros(4).reshape(2,2))
    message=xx.to_html()
    return dict(message = message)
hello3.html文件是

{{extend'layout.html'}

{{=message}

我希望看到一个格式整洁的表作为这样的输出

    0   1
0   0   0
1   0   0
我得到的有点像这样(在这里很难精确地显示,因为如果我粘贴它,实际生成的显示甚至会有所不同)

table border=“1”class=“dataframe”>style=“文本对齐:右;”>/th>0 1 0 0

有人能解释一下我遗漏了什么吗。 如果我将相同的输出粘贴到一个文本文件中,将其另存为html文件,它在浏览器中显示得非常好


是否有其他方式显示数据帧?

默认情况下,web2py会转义模板中写入的任何内容(出于安全目的)。如果要将原始HTML插入模板,必须通过将标记包装到
XML()
helper中来防止转义:

{{=XML(message)}}

谢谢这就解决了问题。