Home > other >  Django pagination has_previous and has_next methods doesn't work
Django pagination has_previous and has_next methods doesn't work

Time:06-09

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 >
        <span >

          {% 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.

CodePudding user response:

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 %}
  • Related