hello i have a microblog app, and i'm trying to paginate the entries, to show only 10 per page, for example. though i've followed the tutorial, my pagination doesn't seem t be working.
the listing function looks like that:
def listing(request):
blog_list = Blog.objects.all()
paginator = Paginator(blog_list, 10)
try:
page = int(request.GET.get('page','1'))
except ValueError:
page = 1
try:
posts = paginator.page(page)
except (EmptyPage, InvalidPage):
posts = paginator.page(paginator.num_pages)
return render_to_response('profile/publicProfile.html', {"posts": posts})
and in my template:
<div class="pagination">
<span class="step-links">
{% if posts.has_previous %}
<a href="?page={{ posts.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ posts.number }} of {{ posts.paginator.num_pages }}.
</span>
{% if object.has_next %}
<a href="?page={{ posts.next_page_number }}">next</a>
{% endif %}
</span>
thanks!