[Django] #34353: ListView paging property did not return

3 views
Skip to first unread message

Django

unread,
Feb 19, 2023, 7:08:25 AM2/19/23
to django-...@googlegroups.com
#34353: ListView paging property did not return
-----------------------------------------+------------------------
Reporter: liyifo | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
{{{
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}

}}}

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.

Django

unread,
Feb 19, 2023, 3:07:57 PM2/19/23
to django-...@googlegroups.com
#34353: ListView paging property did not return
-------------------------------+--------------------------------------
Reporter: Liyifo | Owner: nobody
Type: Bug | Status: closed

Component: Generic views | Version: 4.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Tim Graham):

* 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>

Reply all
Reply to author
Forward
0 new messages