{% load mathfilters %}

{% if page_obj.has_other_pages %}
<div class="pagination">
  <nav aria-label="Page navigation">
    <ul class="pagination">
      {% if page_obj.has_previous %}
      <li class="page-item">
        <a class="page-link" href="?page={{page_obj.number|sub:1}}" aria-label="Previous">
          <span aria-hidden="true">&laquo;</span>
          <span class="sr-only">Previous</span>
        </a>
      </li>
      {% endif %}
      {% for i in page_obj.paginator.page_range %}
      {% if page_obj.number == i %}
        <li class="page-item active">
        <a class="page-link" href="#">{{i}} <span class="sr-only">(current)</span></a>
        </li>
      {% else %}
          <li class="page-item"><a class="page-link" href="?page={{i}}">{{i}}</a></li>
      {% endif %}
      {% endfor %}
      {% if page_obj.has_next %}
      <li class="page-item">
        <a class="page-link" href="?page={{page_obj.number|add:1}}" aria-label="Next">
          <span aria-hidden="true">&raquo;</span>
          <span class="sr-only">Next</span>
        </a>
      </li>
      {% endif %}
    </ul>
  </nav>
</div>
{% endif %}
