[Python] Adding values to cells in a specific column in HTML

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am creating a very basic table in HTML for my Django project. I got some help from Here to learn how to pass a list from my Django app to my HTML and generate rows for my values. My question this time is: how can I target the second, third, or any particular column for my list? For example, suppose I have a list of values and want to add all of them to Column 3 of my table. Here is the code I tried to use where i wanted to have {{ name }} values added to column two, but it keeps adding the cells to the first column


    <html>
    <body>
    <table border="1" cellpadding = "5" cellspacing="5">
    <tr>
    <th> IDs </th>
    <th> Names </th>
    <th> Heights </th>
    </tr>
    {% for id in myIDs %}
    <tr>
    <td>{{ id }}</td>

    </tr>
    {% endfor %}
    <tr>
    {% for name in myNames %}
    <td>
    <tr>
    <td>{{ name }}</td>
    </tr>
    </td>
    {% endfor %}
    </tr>
    </table>
    </body>
    </html>

    Continue reading...

Compartilhe esta Página