Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django pagination has_previous and has_next methods doesn't work

I’m using pagination in Django 1.11. But when I use has_next and has_previous it returns false everytime. Don’t print anything. I’m sure that there is previous and next pages. In views I’m using TableView which is like ListView. Here is my code:

<div class="pagination">
        <span class="step-links">

          {% if customers.has_next %}
            <p>HAS NEXT</p>
          {% endif %}
          {% if customers.has_previous %}
            <p>HAS PREVİOUS</p>
          {% endif %}




        </span>
      </div>

views.py

class TableView(ExportMixin, SingleTableView):
    model = Customer
    table_class = CustomerTable
    template_name = 'admin_pages/user_admin_page.html'
    context_object_name = 'customers'
    paginate_by = 3

*I’m using tableview just for export table.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should work with the page_obj object, so:

{% if page_obj.has_next %}
  <p>HAS NEXT</p>
{% endif %}
{% if page_obj.has_previous %}
  <p>HAS PREVİOUS</p>
{% endif %}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading