#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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070186699339a0-bd271aac-d98f-42ca-9e13-2980ed04a2e4-000000%40eu-central-1.amazonses.com.