{% if page_obj.has_previous %} Previous {% else %} Previous {% endif %} {% for num in page_obj.paginator.page_range %} {% if page_obj.number == num %} {{ num }} {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %} {{ num }} {% elif num == 1 or num == page_obj.paginator.num_pages %} {{ num }} {% elif forloop.first or forloop.last %} ... {% endif %} {% endfor %} {% if page_obj.has_next %} Next {% else %} Next {% endif %}