Last active
          November 27, 2024 00:06 
        
      - 
      
- 
        Save archatas/e9ce34df0ba4ecef13b69982d47e4119 to your computer and use it in GitHub Desktop. 
    Bootstrap 4 pagination using only https://pypi.org/project/django-query-params/
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | {% load query_params_tags %} | |
| {% if page_obj.has_other_pages %} | |
| <nav aria-label="Pagination"> | |
| <ul class="pagination"> | |
| {% if page_obj.has_previous %} | |
| <li class="page-item"> | |
| <a href="{% modify_query page=page_obj.previous_page_number %}" class="page-link">Previous</a> | |
| </li> | |
| {% else %} | |
| <li class="page-item disabled"> | |
| <span class="page-link">Previous</span> | |
| </li> | |
| {% endif %} | |
| {# Handle first page and ellipsis before current page #} | |
| {% if page_obj.number > 3 %} | |
| <li class="page-item"> | |
| <a href="{% modify_query page=1 %}" class="page-link">1</a> | |
| </li> | |
| {% if page_obj.number > 4 %} | |
| <li class="page-item disabled"> | |
| <span class="page-link">...</span> | |
| </li> | |
| {% endif %} | |
| {% endif %} | |
| {# Generate page numbers around the current page #} | |
| {% for i in page_obj.paginator.page_range %} | |
| {% if i|add:"-2" <= page_obj.number and i|add:"2" >= page_obj.number %} | |
| {% if i == page_obj.number %} | |
| <li class="page-item active" aria-current="page"> | |
| <span class="page-link">{{ i }}</span> | |
| </li> | |
| {% else %} | |
| <li class="page-item"> | |
| <a href="{% modify_query page=i %}" class="page-link">{{ i }}</a> | |
| </li> | |
| {% endif %} | |
| {% endif %} | |
| {% endfor %} | |
| {# Handle last page and ellipsis after current page #} | |
| {% if page_obj.number < page_obj.paginator.num_pages|add:"-2" %} | |
| {% if page_obj.number < page_obj.paginator.num_pages|add:"-3" %} | |
| <li class="page-item disabled"> | |
| <span class="page-link">...</span> | |
| </li> | |
| {% endif %} | |
| <li class="page-item"> | |
| <a href="{% modify_query page=page_obj.paginator.num_pages %}" | |
| class="page-link">{{ page_obj.paginator.num_pages }}</a> | |
| </li> | |
| {% endif %} | |
| {% if page_obj.has_next %} | |
| <li class="page-item"> | |
| <a href="{% modify_query page=page_obj.next_page_number %}" class="page-link">Next</a> | |
| </li> | |
| {% else %} | |
| <li class="page-item disabled"> | |
| <span class="page-link">Next</span> | |
| </li> | |
| {% endif %} | |
| </ul> | |
| </nav> | |
| {% endif %} | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment