Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mattions
Created December 8, 2014 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattions/26046fe94d51045e7663 to your computer and use it in GitHub Desktop.
Save mattions/26046fe94d51045e7663 to your computer and use it in GitHub Desktop.
{% 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