<ul class="pagination blog-pagination">
    {% if page_obj.has_previous %}
        <li class="page-item"><a href="?page=1">первая</a></li>
        <li class="page-item"><a href="?page={{ page_obj.previous_page_number }}">Назад</a></li>
    {% else %}
        <li class="page-item disabled"><span class="page-link">первая</span></li>
        <li class="page-item disabled"><span class="page-link">Назад</span></li>
    {% endif %}
    {% for i in paginator.page_range %}
        {% if page_obj.number == i %}
            <li><a href="#">{{ i }}</a></li>
        {% elif i > page_obj.number|add:'-3' and i < page_obj.number|add:'3' %}
            <a href="?page={{ i }}">{{ i }}</a>
        {% endif %}
    {% endfor %}
    {% if page_obj.has_next %}
        <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">Вперед</a></li>
        <li class="page-item"><a href="?page={{ page_obj.paginator.num_pages }}">последняя</a></li>
    {% else %}
        <li class="page-item disabled">
            <span class="page-link">Вперед</span>
            <span class="page-link">последняя</span>
        </li>
    {% endif %}
</ul>