Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Django pagination with bootstrap

I am about to add a pagination to my list of contacts. I am sitting over it the whole day and have no idea what I mixed up. Important thing is that I do have a working filters - so I can narrow the list. But from my understanding pagination should work anyway. In my case I see nothing so my guess is first "if" fails. If you could point me in the right direction. Best regards.

Views.py

def ContactsList(request):

    contacts_list = Contact.objects.all()
    Contacts_filter = LFilter(request.GET, queryset=contacts_list)

    #pagination
    page = request.GET.get('page', 1)
    paginator = Paginator(contacts_list, 20)

    try:
        contacts = paginator.page(page)
    except PageNotAnInteger:
        contacts = paginator.page(1)
    except EmptyPage:
        contacts = paginator.page(paginator.num_pages)
    return render(request, 'index.html', context, {'filter': contacts_filter})

Template part:

{% if contacts.has_other_pages %}
  <ul class="pagination">
    {% if contacts.has_previous %}
      <li><a href="?page={{ contacts.previous_page_number }}">&laquo;</a></li>
    {% else %}
      <li class="disabled"><span>&laquo;</span></li>
    {% endif %}
    {% for i in contacts.paginator.page_range %}
      {% if library.number == i %}
        <li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
      {% else %}
        <li><a href="?page={{ i }}">{{ i }}</a></li>
      {% endif %}
    {% endfor %}
    {% if contacts.has_next %}
      <li><a href="?page={{ contacts.next_page_number }}">&raquo;</a></li>
    {% else %}
      <li class="disabled"><span>&raquo;</span></li>
    {% endif %}
  </ul>
{% endif %}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

problem with this line:

return render(request, 'index.html', context, {'filter': contacts_filter})

here you are passing the context as filter only and missing contacts

so change this to

return render(request, 'index.html', context, {'filter': contacts_filter,'contacts': contacts})
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!