Skip to content Skip to sidebar Skip to footer

How To Format Jinja Tables

I have a table that I am trying to display a table properly on a flask HTML site. my python file is @app.route('/test', methods=['GET']) def LoadTest(): global USERS,STARTTIME,

Solution 1:

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>

Post a Comment for "How To Format Jinja Tables"