如何格式化Jinja表 [英] How to format jinja tables

查看:54
本文介绍了如何格式化Jinja表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,试图在烧瓶HTML网站上正确显示表.

I have a table that I am trying to display a table properly on a flask HTML site.

我的python文件是

my python file is

@app.route('/test', methods=['GET'])
def LoadTest():
    global USERS,STARTTIME,ENDTIME,SUBTYPE,SUBSTATUS,USAGE
    CollectValues()
    titles = ['USERS','STARTTIME','ENDTIME','SUBTYPE','SUBSTATUS','USAGE']
    return render_template('Test.html', data1 = USERS , data2 = STARTTIME ,titles = titles)

我当前的html代码是

My current html code is

  <table>
{% for item in titles %}
   <th class="c1">{{item}}</th>
{% endfor %}
{% for dater in data1 %}
  <tr><td class="c2">{{dater}}</td></tr>
{% endfor %}

{% for dater2 in data2 %}
<tr><td>{{dater2}}</td></tr>
{% endfor %}

但是,这会将表格输出为

However, this outputs the table as

USERS   STARTTIME   ENDTIME     SUBTYPE     SUBSTATUS   USAGE
cody
mimic
james
7/10/2020
7/11/2020
7/12/2020

我正在尝试像这样格式化表格

I am trying to format the table like this

USERS   STARTTIME   ENDTIME     SUBTYPE     SUBSTATUS   USAGE
cody    7/10/2020   8/10/2020   Premium     Active       15GB
mimic   7/11/2020   8/11/2020   Premium     Active       15GB
James   7/12/2020   8/12/2020   Premium+    Active       25GB

所有要放在表格标题下方的表格内容均在列表中.我有一个用户,开始时间,结束时间,子类型,子状态和使用情况的列表.我很难获得正确的格式.我继续谈到它们堆叠的问题.

All of the Table content meant to go below the Table headers are in lists. I have a list for Users, Starttime, Endtime, Subtype, Substatus, And Usage. I am having difficulty getting this properly formatted. I keep coming back to the issue of them stacking.

推荐答案

我认为以下方法可以解决您的问题.

I think the following should solve your problem.

@app.route('/test', methods=['GET'])
def load_test():
  global USERS,STARTTIME,ENDTIME,SUBTYPE,SUBSTATUS,USAGE
  CollectValues()
  titles = ['USERS','STARTTIME','ENDTIME','SUBTYPE','SUBSTATUS','USAGE']
  dataset = zip(USERS, STARTTIME, ENDTIME, SUBTYPE, SUBSTATUS, USAGE)
  return render_template('test.html', titles=titles, data=dataset)

<table>
  <thead>
    <tr>
    {% for item in titles %}
      <th class="c1">{{item}}</th>
    {% endfor %}
    </tr>
  </thead>
  <tbody>
  {% for user, starttime, endtime, subtype, subsstatus, usage in data %}
    <tr>
      <td class="c2">{{user}}</td>
      <td class="c2">{{starttime}}</td>
      <td class="c2">{{endtime}}</td>
      <td class="c2">{{subtype}}</td>
      <td class="c2">{{substatus}}</td>
      <td class="c2">{{usage}}</td>
    </tr>
  {% endfor %}
  </tbody>
</table>

这篇关于如何格式化Jinja表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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