Skip to content Skip to sidebar Skip to footer

Django Foorloop Counter Restarts In A New Page

currently I'm writing a simple todolist with django. I have a view and html file for showing the list of items, and I want a number for each task in the table starting from 1. I'm

Solution 1:

You can try to build your own template tag and use it on the template like below :-

@register.filterdefadjust_for_counter(value, page):
    value, page = int(value), int(page)
    counter_value = value + ((page - 1) * settings.RESULTS_PER_PAGE)
    return counter_value

and call it like below in the html :-

{{ forloop.counter|adjust_for_pagination:page }}

For more details you can refer to below link :- https://djangosnippets.org/snippets/1391/

Post a Comment for "Django Foorloop Counter Restarts In A New Page"