1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to get forloop.counter inside two forloops

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have a for loop inside another for loop and im trying to get the index (forloop.counter) from the inner loop. Django is for some reason giving me only the outer index.

    {% for category in categories %}
    {% for product in products %}
    {% if product.category.name == category.name %}
    <p>This is the amount of products inside this category: {{ forloop.counter }}<p>
    {% endif %}
    {% endfor %}
    {% endfor %}

    Continue reading...

Compartilhe esta Página