Skip to content Skip to sidebar Skip to footer

Is_paginated Not Working For Django Generic Views

I've been using django built-in pagination (is_paginated) in few of my pages. They are all working fine. Except for the search page where the pagination should only appear based on

Solution 1:

It's working

views.py

classUserListView(ListView):
    model = User
    template_name = 'user_list.html'
    context_object_name = 'users'
    paginate_by = 10defget_queryset(self):
        return User.objects.all()

templates/user_list.html

  {% if is_paginated %}
  <navaria-label="Page navigation conatiner"><ulclass="pagination justify-content-center">
      {% if page_obj.has_previous %}
      <li><ahref="?page={{ page_obj.previous_page_number }}"class="page-link">&laquo; PREV </a></li>
      {% else %}
      <liclass="disabled page-item"><aclass="page-link">PREV !</a></li>
      {% endif %}

      {% for i in  %}
        {{ i }}
      {% endfor %}

      {% if page_obj.has_next %}
      <li><ahref="?page={{ page_obj.next_page_number }}"class="page-link"> NEXT &raquo;</a></li>
      {% else %}
      <liclass="disabled page-item"><aclass="page-link">NEXT !</a></li>
      {% endif %}
    </ul></nav></div>
{% endif %}

Post a Comment for "Is_paginated Not Working For Django Generic Views"