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}
}}}
docs[https://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>>"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34353>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => invalid
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34353#comment:1>