<div class="row">
    <div class="col-sm-12">
        <div class="text-center">
            <ul class="pagination">
                {% if page_obj.number != 1 %}
                    <li><a href="?q_type={{ request.GET.q_type }}&amp;q={{ request.GET.q }}&amp;order={{ request.GET.sort }}&amp;page=1">first</a></li>
                {% else %}
                    <li class="disabled"><span>first</span></li>
                {% endif %}

                {% if page_obj.has_previous %}
                    <li><a href="?q_type={{ request.GET.q_type }}&amp;q={{ request.GET.q }}&amp;order={{ request.GET.sort }}&amp;page={{ page_obj.previous_page_number }}">prev</a></li>
                {% else %}
                    <li class="disabled"><span>prev</span></li>
                {% endif %}

                {% for page in page_obj.paginator.page_range %}
                    {% if page_obj.number == page %}
                        <li class="active"><span>{{ page }}</span></li>

                    {% else %} {% if page > page_obj.number|add:"-6" and page < page_obj.number|add:"6"  %}
                        <li>
                            <a href="?q_type={{ request.GET.q_type }}&amp;q={{ request.GET.q }}&amp;order={{ request.GET.sort }}&amp;page={{ page }}">
                                {{ page }}
                            </a>
                        </li>
                    {% endif %}{% endif %}
                {% endfor %}

                {% if page_obj.has_next %}
                    <li><a href="?q_type={{ request.GET.q_type }}&amp;q={{ request.GET.q }}&amp;order={{ request.GET.sort }}&amp;page={{ page_obj.next_page_number }}">next</a></li>
                {% else %}
                    <li class="disabled"><span>next</span></li>
                {% endif %}

                {% if page_obj.number != page_obj.paginator.num_pages %}
                    <li><a href="?q_type={{ request.GET.q_type }}&amp;q={{ request.GET.q }}&amp;order={{ request.GET.sort }}&amp;page={{ page_obj.paginator.num_pages }}">last</a></li>
                {% else %}
                    <li class="disabled"><span>last</span></li>
                {% endif %}
            </ul>
        </div>
    </div>
</div>
