在 Python Flask 中使用 render_template 时如何更改表格样式? [英] how do i change table style when using render_template in Python Flask?

查看:82
本文介绍了在 Python Flask 中使用 render_template 时如何更改表格样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Flask、html 和 css 制作网站,我使用 Pandas 读取 csv 文件,进行一些计算并在我的 html 中给我一个表格.如何更改表格的样式?还有如何并排打印表格?

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?

这是烧瓶位

@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'),

这是 html 位:

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

推荐答案

如何更改表格的样式?

如果您使用 pandas.DataFrame.to_html 它确实接受 classes,所以如果你准备了 CSS 类说 mytable 那么它应该足以添加 classes=["mytable"] 在你调用 df.to_html 的地方(其中 dfpandas.DataFrame)

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)

这篇关于在 Python Flask 中使用 render_template 时如何更改表格样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆