#34353 closed Bug (invalid)

ListView paging property did not return

Reported by: Liyifo Owned by: nobody
Component: Generic views Version: 4.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

class ProductListView(ListView):
    template_name = 'product.html'
    model = Products
    paginate_by = 2
    context_object_name = 'products'

    def get_queryset(self):
        queryset = self.model.objects.all().filter(category_id=self.kwargs['pk'])
        return queryset

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['information'] = BaseInformation.objects.first()
        context['classification'] = ProductCategory.objects.all()
        context['news'] = News.objects.filter(is_top=True).filter(is_published=True)
        context['category'] = ProductCategory.objects.filter(pk=self.kwargs['pk']).first()
        print('****************')
        print(context)
        print(context['paginator'].__dict__)
        print(context['page_obj'].__dict__)
        return context

result:

****************
{'paginator': <django.core.paginator.Paginator object at 0x00000258B07A6E20>, 'page_obj': <Page 2 of 2>, 'is_paginated': True, 'object_list': <QuerySet 
[<Products: test3>]>, 'products': <QuerySet [<Products: test3>]>, 'view': <web.views.ProductListView object at 0x00000258B07A6F70>, 'information': <Base
Information: 公司基本信息>, 'classification': <QuerySet [<ProductCategory: 藤仓气缸经济型>, <ProductCategory: 接头、调速阀>, <ProductCategory: 藤仓专区>
]>, 'news': <QuerySet [<News: 1231231>, <News: 节日放假通知>]>, 'category': <ProductCategory: 藤仓气缸经济型>}
{'object_list': <QuerySet [<Products: test>, <Products: test2>, <Products: test3>]>, 'per_page': 2, 'orphans': 0, 'allow_empty_first_page': True, 'count
': 3, 'num_pages': 2}

docshttps://docs.djangoproject.com/zh-hans/4.1/topics/pagination/
The "page_obj. next_page_number" and other attributes mentioned in the document do not exist

My web page returns results

href="?page=<bound method Page.next_page_number of <Page 2 of 2>>"

Change History (1)

comment:1 by Tim Graham, 21 months ago

Resolution: invalid
Status: newclosed

I can't tell what the issue is, but most likely it's a usage mistake rather than a bug in Django. See TicketClosingReasons/UseSupportChannels for ways to get help. Please reopen the ticket with additional information if you confirm a bug in Django.

Note: See TracTickets for help on using tickets.
Back to Top