W
W
Wayne2019-12-26 22:48:52
Django
Wayne, 2019-12-26 22:48:52

Why don't pagination methods work?

index.html

<span class="current">  
   Страница {{ page }} из{{ page.paginator.num_pages }}.  
    </span>

views.py
def index(request):
  news = News.objects.order_by("date")
  paginator = Paginator(news, 16)
  page = request.GET.get('page')
  try:  
    posts = paginator.page(page)  
  except PageNotAnInteger:  
    posts = paginator.page(1)  
  except EmptyPage:  
    posts = paginator.page(paginator.num_pages)
  context = {
  'page': page,
  'posts': posts
  }
  return render(request, 'index.html', context)

The posts are showing, the pages are working, but the page.paginator.num_pages method is not working.
What could be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2019-12-26
@alexkom6

And where does page get the paginator property from?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question