I am using the django paginator in the template. Its working ok, but not good when there\'s large numbers of pages.
views.py:
def blog(request):
Inspired by @Pavel1114 and @Inti. Removed the arrow at the beginning and at the end as they are not that useful. Added The first page and last page for faster accessing.
-
{{paginator.count}} total
{% if data.number|add:'-4' > 1 %}
- 1
- …
{% endif %}
{% for i in data.paginator.page_range %}
{% if data.number == i %}
- {{ i }}
{% elif i > data.number|add:'-3' and i < data.number|add:'3' %}
- {{ i }}
{% endif %}
{% endfor %}
{% if data.paginator.num_pages > data.number|add:'4' %}
- …
- {{ data.paginator.count }}
{% endif %}