counter in django template

You can create a counter in a Django template using the for loop and the forloop.counter variable. Here's how you can do it:

{% for item in items %}
    {{ forloop.counter }}. {{ item.name }}
{% endfor %}

Explanation: 1. The {% for item in items %} initiates the for loop in the Django template, where "item" is the loop variable and "items" is the iterable object. 2. Inside the for loop, {{ forloop.counter }} is used to display the current iteration count starting from 1. 3. {{ item.name }} is the content of the current item in the iteration. 4. The {% endfor %} tag marks the end of the for loop block.