pip install django-pure-pagination
settings.py
INSTALLED_APPS = (
...
'pure_pagination',
)
PAGINATION_SETTINGS = {
'PAGE_RANGE_DISPLAYED': 10,
'MARGIN_PAGES_DISPLAYED': 2,
'SHOW_FIRST_PAGE_WHEN_INVALID': True,
}
from django.core.paginator import Paginator
from pure_pagination import Paginator
https://github.com/jamespacileo/django-pure-pagination
# views.py
from django.shortcuts import render_to_response
from pure_pagination import Paginator, EmptyPage, PageNotAnInteger
def index(request):
try:
page = request.GET.get('page', 1)
except PageNotAnInteger:
page = 1
objects = ['john', 'edward', 'josh', 'frank']
# Provide Paginator with the request object for complete querystring generation
p = Paginator(objects, request=request)
people = p.page(page)
return render_to_response('index.html', {
'people': people,
}
{# index.html #}
{% extends 'base.html' %}
{% block content %}
{% for person in people.object_list %}
<div>
First name: {{ person }}
</div>
{% endfor %}
{# The following renders the pagination html #}
<div id="pagination">
{{ people.render }}
</div>
{% endblock %}