Skip to content

Instantly share code, notes, and snippets.

@mattions mattions/pagination
Created Dec 8, 2014

Embed
What would you like to do?
{% if is_paginated %}
<div class="col-md-offset-4">
<ul class="pagination pagination-centered">
{% if page_obj.has_previous %}
<li><a href="?page=1"><<</a></li>
<li><a href="?{{queries.urlencode}}&amp;page={{ page_obj.previous_page_number }}"><</a></li>
{% endif %}
{% for i in paginator.page_range %}
<li {% if page_obj.number == i %} class="active" {% endif %}><a href="?{{queries.urlencode}}&amp;page={{i}}">{{i}}</a></li>
{% endfor %}
{% if page_obj.has_next %}
<li><a href="?{{queries.urlencode}}&amp;page={{ page_obj.next_page_number }}">></a></li>
<li><a href="?{{queries.urlencode}}&amp;page={{ page_obj.paginator.num_pages }}">>></a></li>
{% endif %}
</ul>
</div>
{% endif %}
def get_context_data(self, **kwargs):
context = super(ViewClassNameHere, self).get_context_data(**kwargs)
queries_without_page = self.request.GET.copy()
if queries_without_page.has_key('page'):
del queries_without_page['page']
context['queries'] = queries_without_page
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.