Answer the question
In order to leave comments, you need to log in
How to implement pagination in Django?
I googled the question and searched, and on the example of this ( Adjusting pagination in django? ) post, I saw pagination, but for some reason it does not work miraculously, since the author
has views.py
def index(request):
film_list = films_script.Post.objects.all()
paginator = Paginator(film_list, 4) # Show 25 contacts per page
page = request.GET.get('page')
try:
films = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
films = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
films = paginator.page(paginator.num_pages)
context = {
'films': films
}
return render(request, 'index.html', context)
Answer the question
In order to leave comments, you need to log in
It looks like you are using a Querieset instead of a Paginator in your template. You need to pass the paginator to the context
and use it in the template instead of films . And films should be displayed separately, because this is a list with instances.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question