D
D
Dmitry2018-05-11 13:18:12
Django
Dmitry, 2018-05-11 13:18:12

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)

index.html
https://jsfiddle.net/gc0u72L6/1/
I could be wrong

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Grigoriev, 2018-05-11
@ipatov_dn

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 question

Ask a Question

731 491 924 answers to any question