Step 7 (S-61738)

From Stepik Wiki
Jump to: navigation, search

Step on Stepik: https://stepik.org/lesson/14831/step/7

В каком примере приведен правильный способ использования пагинатора ?

A)


from django.core.paginator import Paginator

def view(request):
    articles = Article.objects.all()
    articles = Paginator(articles, 10, request.GET.get('page', 1))

B)

from django.core.paginator import Paginator

def view(request):
    articles = Article.objects.all()
    paginator = Paginator(articles, request.GET['limit'])
    page = paginator.page(request.GET['page'])
C)

from django.core.paginator import Paginator

def view(request):
    articles = Article.objects.all()
    paginator = Paginator(Article.objects.all(), 30, page=2)
    articles = paginator.paginate()

D)

from django.core.paginator import Paginator

def view(request):
    try:
        limit = int(request.GET.get('limit', 10))
    except:
        limit = 10
    try:
        page = int(request.GET.get('page', 1))
    except:
        page = 1
    paginator = Paginator(Article.objects.all(), limit)
    articles = paginator.page(page)