title: How to iterate over a list in django templates?
body: <p>I'm passing 4 lists of the same length and the length of the lists to my template. How do I iterate over the lists?</p>
  
  <p>views.py</p>
  
  <pre><code>def allbooks(request):
      ID = [1,2]
      bookName = ["Python", "Java"]
      author = ["idk", "who"]
      copies = [3,7]
      return render(request, 'allbooks.html',{'ID':ID,'bookName':bookName, 'author':author, 'copies':copies,'range':range(len(ID))})
  </code></pre>
  
  <p>allbooks.html</p>
  
  <pre><code>{% extends 'base.html' %}
  
  {% block content %}
  {% if user.is_authenticated %}
  &lt;div&gt;
      &lt;h3&gt;
          List of books:
      &lt;/h3&gt;
      &lt;table class="table"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;ID&lt;/th&gt;
                  &lt;th&gt;Book Name&lt;/th&gt;
                  &lt;th&gt;Author&lt;/th&gt;
                  &lt;th&gt;Number of copies&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              {% for x in range %}
                  &lt;tr&gt;
                      &lt;td&gt;{{id[x]}}&lt;/td&gt;
                      &lt;td&gt;{{bookName[x]}}&lt;/td&gt;
                      &lt;td&gt;{{author[x]}}&lt;/td&gt;
                      &lt;td&gt;{{copies[x]}}&lt;/td&gt;
                  &lt;/tr&gt;
              {% endfor %}
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;    
  {% else %}
      &lt;h3&gt;You must login to continue.&lt;/h3&gt;    
  {% endif %}
  {% endblock %}
  </code></pre>
  
  <p>I've tried replacing the variable x with {% forloop.counter0 %} but to no avail. How can I fix this?</p>