Wednesday, October 22, 2014

How do I display list of pages with a ListView object?

Hi,
How do I display list of pages with a ListView object?  For example display a link for each page (except maybe the current page):
previous 1 2 3 4 next

Currently I use the following in a view to display "previous" and "next":
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
{% endif %}

I tried using a for loop with a template tag and a reference to page_obj, but I could not get it to work.  Any ideas?

Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f7a78b07-400c-4b54-aba3-c131bae58982%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment