Table does not want to be vertical

Asked

Viewed 37 times

0

I wanted to know what I’m doing wrong, because I created a table in the template taking information from an api. Wanted to order themselves vertically and not in the orizontal.

inserir a descrição da imagem aqui

    <!Doctepy html>

<html>
    <head>
        <title>Teste de Requests</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <table border="1">
            <tr>
                <th bgcolor="red">Pilotos</th>
            </tr>
            <tr>
                {% for i in range(200) %}
                    {% if "IFATC" in data[i]['DisplayName'] %}
                        <td align= middle width=100>{{data[i]['DisplayName']}}</td>
                    {% endif %}
                {% endfor %}
            </tr>
        </table>
    </body>

2 answers

0

For each table row you must also have your own TR (Row table):

{% for i in range(200) %}
    {% if "IFATC" in data[i]['DisplayName'] %}
    <tr>
        <td align=middle width=100>{{data[i]['DisplayName']}}</td>
    </tr>
    {% endif %}
{% endfor %}

That is, put the TR inside the loop so that they too are repeated.

A tip, avoid using the formatting attributes directly in the HTML tags and do the formatting directly using CSS, the maintenance of code and layout changes will be much simpler.

  • Thanks for the help, with your tip I solved the problem

-1

It’s very simple, buddy. The code in the structure below will generate a horizontal table. Each new block of TR codes will generate a row with cells.

<tr>
       <td></td>
             ...
         <td></td>
</tr>

Already in the following code, we will have each new TR block containing a single cell, will generate a vertical table.

<tr>
       <td></td>
</tr>
      ...
<tr>
       <td></td>
</tr>

But the vertical table can have more than one cell as well. So, as the friend said above, depending on how you make the loop, the result may vary.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.