def get_paginators(request, objects, per_page=20, paginator_range=5): paginator_range = int(paginator_range) from django.core.paginator import Paginator, InvalidPage, EmptyPage paginator = Paginator(objects, per_page) # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 # If page request (9999) is out of range, deliver last page of results. try: obj_list = paginator.page(page) except (EmptyPage, InvalidPage): obj_list = paginator.page(paginator.num_pages) if obj_list.number-paginator_range >= 0: from_ = obj_list.number-paginator_range else: from_ = 0 if obj_list.number+paginator_range <= len(paginator.page_range): to_ = obj_list.number+paginator_range else: to_ = len(paginator.page_range) page_range = paginator.page_range[from_:to_] return (obj_list, page_range) # Use follwing code in your template to show page_range {% for item in page_range %} {% ifequal item event_list.number %} {{item}} {% else %} {{item}} {% endifequal %} {% endfor %}