【发布时间】:2016-01-13 10:37:15
【问题描述】:
在https://django-endless-pagination.readthedocs.org/en/latest/twitter_pagination.html 上,我了解到views.py 的示例可能如下所示:
from endless_pagination.decorators import page_template
@page_template('myapp/entry_index_page.html') # just add this decorator
def entry_index(
request, template='myapp/entry_index.html', extra_context=None):
context = {
'entries': Entry.objects.all(),
}
if extra_context is not None:
context.update(extra_context)
return render_to_response(
template, context, context_instance=RequestContext(request))
这似乎表明我们必须调用Entry.objects.all() 并将结果传递给模板。但是Entry.objects.all() 不是已经发出查询调用来检索所有相应的数据库对象,从而违背了分页的主要目标之一(一次检索小块数据)吗?
【问题讨论】:
-
查询集是惰性的。我不知道这个是什么时候评估的(因此不能提供一个可靠的答案),但是在使用
.all()之后可以继续.filter()。
标签: python django pagination django-endless-pagination