nendere
nendere

Reputation: 31

how do i change table style when using render_template in Python Flask?

i'm making a website using flask, html and css, i use pandas to read a csv file, do some calculations and give me a table in my html. how can i change the style of the table? also how can i print the tables side by side?

here's the flask bit

@app.route('/')
def about():
    data = df[['attempts', 'activity']]
    data = data.groupby('activity').sum().sort_values('attempts', ascending=False).reset_index()

    datas = df[['grade', 'activity']]
    datas = datas.groupby('activity').sum().sort_values('grade', ascending=False).reset_index()
    return render_template("about.html", data=data.to_html(header='true'), data1=datas.to_html(header='true'),

here's the html bit:

    <section id="problems">
        <h2>problems</h2>
        <p class="lead">{{data | safe}} {{data1 |safe}}</p>
    </section>

Upvotes: 1

Views: 879

Answers (2)

Antonialieb
Antonialieb

Reputation: 47

You can use css to customize the outcome of your html code. For example you‘ve created a css file you can refer the class „lead“ from the current code and change colors, margin and many more. To get started take a look at what exactly you want to change and look how it will work with css/html. For tables you probably need to change your html and add a table and store your current html code in there, something like for tabledata and for table row and put the data you want to display in it. I hope this get‘s you started, so you know where you can look it up!

Upvotes: 0

Daweo
Daweo

Reputation: 36510

how can i change the style of the table?

If you are using pandas.DataFrame.to_html it does accept classes, so if you have prepared CSS class say mytable then it should be enough to add classes=["mytable"] where you call df.to_html (where df is pandas.DataFrame)

Upvotes: 2

Related Questions