Skip to content

Instantly share code, notes, and snippets.

@JuniorLima
Created April 26, 2012 18:24
Show Gist options
  • Save JuniorLima/2501651 to your computer and use it in GitHub Desktop.
Save JuniorLima/2501651 to your computer and use it in GitHub Desktop.
Dúvida na paginação do Django
<div id="paginac">
<div id="botoes">
{% if notipage.has_previous %}
<a href="?page={{ notipage.previous_page_number }}">
<div id="botnBack"></div>
</a>
{% endif %}
{% if notipage.has_next %}
<a href="?page={{ notipage.next_page_number }}">
<div id="botnLeft"></div>
</a>
{% endif %}
</div>
</div>
def ultimas(request):
noticias = Noticia.objects.all().order_by('datapublicacao').filter(publicar__icontains=1)
paginacao = Paginator(noticias, 2)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
notipage = paginacao.page(page)
except (EmptyPage, InvalidPage):
notipage = paginacao.page(paginacao.num_pages)
return render_to_response('Scope/ultimas.html',locals(),context_instance=RequestContext(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment