Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8804623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:39:15+00:00 2026-06-14T01:39:15+00:00

I am trying to create HTML tables from data stored in a table. My

  • 0

I am trying to create HTML tables from data stored in a table. My data is read from a table and converted into a dict of lists, e.g.:

x = {'date':[u'2012-06-28', u'2012-06-29', u'2012-06-30'], 'users': [405, 368, 119]}

My goal is to create an HTML table with the following structure for an arbitrary list length:

<table>
  <thead>
    <th>Date</th>
    <th>Users</th>
  </thead>

  <tbody>      
    <tr>
      <td>2012-06-28</td>
      <td>405</td>
    </tr>
    <tr>
      <td>2012-06-29</td>
      <td>368</td>
    </tr>
    <tr>
      <td>2012-06-30</td>
      <td>119</td>
    </tr>
  </tbody>
</table> 

I have tried doing this two incorrect ways in my Flask template:

<tbody>
  {% for line in x %}
    <tr>
      <td>{{ x.date|tojson|safe }}</td>
      <td>{{ x.users }}</td>
     </tr>
   {% endfor %}
</tbody>

Which prints the entire list into each column.

And:

{% for date in x.date %}
  <tr><td>{{ date|tojson|safe }}</td></tr>
{% endfor %}

{% for users in x.users %}
  <tr><td>{{ users }}</td></tr>
{% endfor %}

Which simply prints everything into the first column.

These experiments and many other dead ends lead me to believe that there is no simple way to build the table as I would like given my current data structure.

Given this, I have two questions:
1) How would I go about building the table using my current data structure?
2) What is the standard or ideal way to structure data for this use case?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:39:17+00:00Added an answer on June 14, 2026 at 1:39 am

    Like you said, you could either change your data structure, or change your template code. Here is one way to keep the current structure:

    {% for row_index in range(x['date']|count) %}
        <tr>
          <td>{{ x[row_index]['date']|tojson|safe }}</td>
          <td>{{ x[row_index]['users'] }}</td>
        </tr>
    {% endfor %}
    

    Or you could restructure your data in python:

    x = zip(x['date'], x['users'])
    

    And then use this template:

    {% for row in x %}
        <tr>
          <td>{{ row[0]|tojson|safe }}</td>
          <td>{{ row[1] }}</td>
        </tr>
    {% endfor %}
    

    You can also structure the data so that the template does not depend on the order of the cells:

    from itertools import izip
    x = [dict(date=d, user=u) for d, u in izip(x['date'], x['users'])]
    

    Then you can access your data like this:

    {% for row in x %}
        <tr>
          <td>{{ row['date']|tojson|safe }}</td>
          <td>{{ row['user'] }}</td>
        </tr>
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create some dynamic html out of some data from db.
i am trying to create a pdf email using data inputed into a html
Possible Duplicate: outputting values from database into html table PHP I am trying to
I am trying to use HighCharts' HTML-table-to-chart script to create a line graph from
I'm trying to create stand-alone front-end module (HTML, CSS & JS) to integrate into
I'm trying to figure out how to pull data from multiple tables and making
As title states, my objective is to produce an HTML table using data from
I am trying to use the HTML Agility pack to scrape some data from
I am trying to create a BASH script what would extract the data from
I am trying to create a dynamic html table with retractable columns. In real

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.