我正在编写我的第一个网站,其中一个部分是教师班级的所有子用户的列表,所以我如何使用prettytable with flask来获取一个表格我的最终目标是一个看起来像这样的表格(只是数据)
Teacher | Student | Id | GPA | Last sign learned
----------------------------------------------------------------
Medina | John doe | 19500688 | 4.0 | Bad
Medina | Samantha babcock | 91234094 | 2.5 | Toilet
Jonson | Steven smith | 64721881 | 3.0 | Santa
我最好如何使用漂亮的桌子,但任何方法都会很棒!
答案 0 :(得分:0)
你好,所以你的表单很容易创建,但所以让我们从python
开始使用静态信息 def function():
from prettytable import *
table = PrettyTable(["Teacher","Student"," ID","GPA"," Last sign learned "])
table.add_row(["Medina","John doe","19500688","4.0","Bad"])
table.add_row(["Medina","Samantha babcock ","91234094","2.5","Toilet"])
table.add_row(["Jonson","Steven smith","64721881","3.0","Santa"])
return render_template("info.html", tbl=table.get_html_string(attributes = {"class": "foo"}))
现在为您提供HTML:
{%extends "template.html"%}
{{tbl|safe}}