[Django]-Django turn list of objects into a table

5👍

In your views:

context['table_info'] = [['1.1.1.1', 'A'], ['2.2.2.2', 'B']]

Then in your template use a for loop:

  <table>
    <tr>
      <th>Column1</th>
      <th>Column2</th>
    </tr>
    {% for item in table_info %}
      <tr>
        <td>{{ item.0 }}</td>
        <td>{{ item.1 }}</td>
      </tr>
    {% endfor %}
  </table>

Leave a comment