### views.py ### from django.core.paginator import Paginator, InvalidPage, EmptyPage # get any current GET parameters without the page modifier extra_param = request.GET.copy() if 'page' in extra_param.keys(): del extra_param['page'] length = len(object_list) # pagination paginator = Paginator(object_list , 1) # get page number from GET request page_num = request.GET.get('page', 1) # get objects from paginator according to page number try: objects = paginator.page(page_num) except(EmptyPage, InvalidPage): objects = paginator.page(paginator.num_pages) context_dict = { 'object_amount': length, 'objects': objects, 'params' : extra_params, } return render(request, 'search.html', context_dict) ### Template ### <div class="pagination"> <ul> {% if objects.has_previous %} <li><a href="?{{params.urlencode}}&page={{ objects.previous_page_number }}">previous</a></li> {% else %} <li class="disabled">previous</li> {% endif %} {% for page in objects.paginator.page_range %} {% if page == summaries.number %} <li><a class="active" href="?{{params.urlencode}}&page={{ page }}" >{{ page }}</a></li> {% else %} <li><a href="?{{params.urlencode}}&page={{ page }}" >{{ page }}</a></li> {% endif %} {% endfor %} {% if objects.has_next %} <li><a href="?{{params.urlencode}}&page={{ objects.next_page_number }}">next</a></li> {% else %} <li class="disabled">next</li> {% endif %} </ul> </div>