pandas DataFrame to html using Flask

Viewed 3013

I am trying to generate an html page that contains my results. I have the following code:

import pandas as pd
from flask import (Flask, flash, redirect, render_template,
                   request, session, abort)

app = Flask(__name__)

@app.route("/")
def index():
    return "Movies reco app!"


@app.route("/tables")
def show_tables():
    df_ = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6]})
    number = 1224556789
    return render_template('test.html',
                           number=str(number),
                           data = df_.to_html())

if __name__ == "__main__":
    app.run() 

With the templates:

<!DOCTYPE html>
<html>
<body>
<title>Movies Recommendation</title>
<div>

{% block content %}

        <h2> For watching: {{number}} </h2>

        <p>Here are the top numbers: </p>
        <h4>{{data | safe}}</h4>


<img src="http://www.marcustheatres.com/media/images/gallery-images/majestic-cinema-of-brookfield/41-majesticbrookfield-exteriorjpg.jpg"
height="200" width="800">

{% endblock %}
</div>
</body>
</html>

After many corrections, it now generates No error... but an empty page. Any idea what is happening please?

--- after editing the code: it works now, sorry for the trouble.

0 Answers
Related