AnjuT
AnjuT

Reputation: 176

Displaying table data in python flask

I am listing down the data coming from the database in a table. But it is not aligning as a table.

what I want to display in the web page is,

Name       john mark 
Faculty    cs 
University xxx 

But what I get in the web page is,

Name john mark 
Faculty cs 
University xxx

In my .html I have,

{% for item in data %}
<tr>
    <td>{{item[0]}}</td>
    <td>{{item[1]}}</td>
</tr>
<br>
{% endfor %}

Please help me with this as I am new to python flask.

Upvotes: 1

Views: 9634

Answers (2)

BeeBee8
BeeBee8

Reputation: 3074

This is how valid table HTML should look. You have not wrapped tr with <table> element.

<table>
  <tr>
    <th>Firstname</th>
    <th>Lastname</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>
</table>

So your code should look like this.

<table>
{% for item in data %}
<tr>
    <td>{{item[0]}}</td>
    <td>{{item[1]}}</td>
</tr>
{% endfor %}
</table>

Upvotes: 5

Nandita Sharma
Nandita Sharma

Reputation: 13407

Try this html

<table>
    <tbody>
    {% for item in data %}
    <tr>
        <td>{{item[0]}}</td>
        <td>{{item[1]}}</td>
    </tr>
    {% endfor %}
    </tbody>
</table>

Upvotes: 2

Related Questions