0

I am a web2py beginner. I was trying a simple variation of hello3.py in the web2py examples. hello3.py file is

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 file is

{{extend 'layout.html'}}

{{=message}}

I expect to see a neatly formatted table as output like this

    0   1
0   0   0
1   0   0

What I get is somewhat like this.(It is difficult to show it precisely here because if I paste it, the actual display produced is even different)

table border="1" class="dataframe"> style="text-align: right;"> /th> 0 1<> 0 0 0 1 0 0

Can somebody explain what I am missing. If I paste the same output in a textfile , save it as html file, it displays perfectly well in browser.

Is there any other way of displaying a pandas dataframe ?

1 Answers1

0

By default, web2py escapes any content written in the template (for security purposes). If you want to insert raw HTML into the template, you must prevent the escaping by wrapping the markup in the XML() helper:

{{=XML(message)}}
Anthony
  • 25,466
  • 3
  • 28
  • 57