title: django forloop counter as a variable
body: <p>So I am trying to make an e-commerce pizza site where when a user adds an item to the basket it is stored as a cookie in the form
  <code>cart=[{&quot;id&quot;:&quot;2&quot;,&quot;quantity&quot;:&quot;1&quot;},{&quot;id&quot;:&quot;3&quot;,&quot;quantity&quot;:&quot;5&quot;},{&quot;id&quot;:&quot;5&quot;,&quot;quantity&quot;:&quot;3&quot;},{&quot;id&quot;:&quot;5&quot;,&quot;quantity&quot;:&quot;3&quot;}]</code></p>
  <p>And my views.py is...</p>
  <pre><code>def cart(request):
      cart = request.COOKIES.get('cart')
      cart = json.loads(cart)
  
      items =[]
      basket=[]
      for i in cart:
          pizza = Product.objects.filter(pk=i['id']).first()
          basket.append(int(i['quantity']))
          items.append(pizza)
  
      cart = len(cart)
  
      context = {
          &quot;cart&quot;:cart,
          &quot;pizzas&quot;:items,
          &quot;basket&quot;:basket
      }
      return render (request, &quot;store/cart.html&quot;, context)
  </code></pre>
  <p>And my models.py is ...</p>
  <pre><code>class Product(models.Model):
      name = models.CharField(max_length=70)
      price = models.IntegerField()
      description = models.CharField(max_length=300)
      image = models.ImageField(upload_to=&quot;pizza_images&quot;)
  
      def save(self, *args, **kwargs):
          super().save()
          img = Image.open(self.image.path)
  
          img.save(self.image.path)
  
      def __str__(self):
          return f&quot;{self.name}&quot;
  </code></pre>
  <p>In which my template code...</p>
  <pre><code> &lt;table&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th scope=&quot;col&quot; class=&quot;small_col&quot;&gt;Item&lt;/th&gt;
                      &lt;th id=&quot;product_col&quot; scope=&quot;col&quot;&gt;Product&lt;/th&gt;
                      &lt;th scope=&quot;col&quot; class=&quot;small_col&quot;&gt;Quantity&lt;/th&gt;
                      &lt;th scope=&quot;col&quot; class=&quot;small_col&quot;&gt;Price&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
  
              &lt;tbody&gt;
                  {% for pizza in pizzas %}
  
                      &lt;tr&gt;
                          &lt;td class=&quot;center&quot;&gt;{{forloop.counter}}&lt;/td&gt;
                          &lt;td&gt;{{pizza.name}}&lt;/td&gt;
                          &lt;td class=&quot;quantity_row justify-content-center&quot;&gt;
                              &lt;input class=&quot;quantity_input&quot; type=&quot;text&quot; value=&quot;{{basket.forloop.counter0}}&quot; id=&quot;pizza{{forloop.counter}}&quot;&gt;
                              &lt;div class=&quot;form_buttons&quot;&gt;
                                  &lt;img onclick=&quot;add(this.getAttribute('data-attribute'))&quot; data-attribute=&quot;pizza{{forloop.counter}}&quot; src=&quot;https://s.svgbox.net/hero-outline.svg?ic=plus-sm&amp;fill=000&quot; &gt;
                                  &lt;img onclick=&quot;minus(this.getAttribute('data-attribute'))&quot; data-attribute=&quot;pizza{{forloop.counter}}&quot; src=&quot;https://s.svgbox.net/hero-outline.svg?ic=minus-sm&amp;fill=000&quot;&gt;
                              &lt;/div&gt;
                          &lt;/td&gt;
                          &lt;td class=&quot;center&quot;&gt;
                              &lt;h6&gt;$25&lt;/h6&gt;
                          &lt;/td&gt;
                          &lt;td class=&quot;small_col&quot;&gt;
                              &lt;a&gt;&lt;img class=&quot;mb-1&quot; src=&quot;https://s.svgbox.net/hero-outline.svg?ic=trash&amp;fill=d90429&quot; width=&quot;20&quot; height=&quot;20&quot;&gt;&lt;/a&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                          
                  {% endfor %}
  
              &lt;/tbody&gt;
  
          &lt;/table&gt;
  </code></pre>
  <p>And in the input field I want the quantity of the product to be displayed. The line which says...
  <code>&lt;input class=&quot;quantity_input&quot; type=&quot;text&quot; value=&quot;{{basket.forloop.counter0}}&quot; id=&quot;pizza{{forloop.counter}}&quot;&gt;</code>and for somereason the forloop.counter doesn't get the the value of the list and makes it null.</p>
  <p>Any ideas on how i could make it work?
  Thanks!</p>