V
V
Villian_Os2020-08-12 20:18:41
Django
Villian_Os, 2020-08-12 20:18:41

Why does __init__() takes 2 positional arguments but 4 were given error in django?

views.py

class ArchiveReports(ListView):
    context_object_name = 'articles'
    template_name = 'main_application/archive-reports-page.html'

    def get_queryset(self):
        articles = Articles.objects.all()
        # Отбираем первые 10 статей
        paginator = Paginator(articles, 2)
        page = self.request.GET.get('page')
        try:
            articles = paginator.page(page)
        except PageNotAnInteger:
            articles = paginator.page(1)
        except EmptyPage:
            articles = paginator.page(paginator.num_pages)
        return articles


url.py

path('archive/', views.ArchiveReports.as_view(), name='archive_page'),


I found a similar question on the site, the solution was to add _view () to url.py, but I already have it, and I don’t understand what’s the matter. How to get rid of the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-12
@bacon

standard, read the docs for you, how to use Paginator with ListView https://docs.djangoproject.com/en/3.1/topics/pagin...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question