<h3>Page: {{ page.number }} of {{ page.paginator.num_pages }}</h3>
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}
<a href="{% url_add_query page=page.previous_page_number %}">{% endif %}«
Previous
{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}
<a href="{% url_add_query page=page.next_page_number %}">{% endif %}
Next »{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
1 2 3 4 5 6 7 8 9 10 11 12 | @register.simple_tag(takes_context=True)
def url_add_query(context, **kwargs):
request = context.get('request')
get = request.GET.copy()
get.update(kwargs)
path = '%s?' % request.path
for query, val in get.items():
path += '%s=%s&' % (query, val)
return path[:-1]
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Lovely, worked for me when I had filtered querysets with class base views:
#
Please login first before commenting.