djangodjango-formsdjango-pagination

How to Make For Loop Django template. i was makeing a pagination in django


{% for i in paginated_queryset.num_pages %}
    {{ i }}
{% endfor%}

paginated_quertser.num_pages = 9

I want to output like this 1 2 3 4 5 6 7 8 9

I also read django pagination document but in the document not given example like this and I am beginner in django


Solution

  • You can iterate over the .page_range [Django-doc] of the Paginator of the page:

    {% for i in paginated_queryset.paginator.page_range %}
        {{ i }}
    {% endfor %}

    or if this is the Paginator (not the Page), with:

    {% for i in paginator.page_range %}
        {{ i }}
    {% endfor %}