Cannot render values in django template using for loop

So i have a zipped list inside my view and I have passed it into context like this:

 combined_data = zip(hostnames_list, values, values1, values2, values3, values4, values5)

    context = {'combined_data': combined_data}

    

    return render(request, 'base/snmp-table.html', context)

but when i try to render this data into the django template like this, the data is not displayed:

<table>
  <thead>
      <tr>
          <th>Hostname</th>
          <th>Value1</th>
          <th>Value2</th>
          <th>Value3</th>
          <th>Value4</th>
          <th>Value5</th>
          <th>Value6</th>
      </tr>
  </thead>
  <tbody>
  {% for host, val1, val2, val3, val4, val5, val6 in combined_data %}
      <tr>
          <td>{{host}}</td>
          <td>{{val1}}</td>
          <td>{{val2}}</td>
          <td>{{val3}}</td>
          <td>{{val4}}</td>
          <td>{{val5}}</td>
          <td>{{val6}}</td>
      </tr>
  {% endfor %}
  </tbody>
</table>

  
  </table>
  <script type="text/javascript">
    setTimeout(function () { 
      location.reload();
    }, 2 * 1000);
  </script>

The lists which are zipped are not empty because when i do this inside my view:

for host, val1, val2, val3, val4, val5, val6 in combined_data:
        print(host, val1, val2, val3, val4, val5, val6)

I get the output in my console

10.1.1.1 not found not found not found not found not found not found
10.1.1.2 not found not found not found not found not found not found

Note: 'not found' is the value inside list. Any insight please? thank you

The problem was that the zip function returns an iterator, which can only be iterated over once. To fix this, you can convert the zipped object to a list by using the list() function, like so: combined_data = list(zip(hostnames_list, values, values1, values2, values3, values4, values5)). This way, you can iterate over the combined_data variable multiple times in your template.

Back to Top