简体   繁体   English

Django 分页器和压缩

[英]Django paginator and zipping

I want to iterate a list and query set in my html render, but am unable to get the Django paginator to work.我想在我的 html 渲染中迭代一个列表和查询集,但我无法让 Django 分页器工作。 I zipped the list and queryset so I could iterate them together.我压缩了列表和查询集,以便可以将它们迭代在一起。 Here's my views.py code.这是我的 views.py 代码。

Oddly enough, I am able to access the data in both lists with {% for item1, item2 in posts %}, but {{ posts.next_page_number }} is just blank.奇怪的是,我能够使用 {% for item1, item2 in posts %} 访问两个列表中的数据,但 {{ posts.next_page_number }} 只是空白。 How can I access the page in the templating engine?如何访问模板引擎中的页面?

Your item2 is the Page object as you zipped it second.你的item2Page object,因为你第二次压缩它。 So presumably you would do it as follows…所以大概你会做如下......

{{ item2.next_page_number }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM