调用 Entry.object.all() 不会破坏 Django 无限分页的意义吗?
Doesn't calling Entry.object.all() defeat the point of Django endless pagination?
在 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()
是否已经进行了查询调用以检索所有相应的数据库对象,从而破坏了分页的主要目标之一(一次检索小块数据)?
Django 中的查询是惰性的,这意味着 Entry.objects.all() 不会带来完整的条目列表,它只是指定 Endless 将显示的结果范围。
在 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()
是否已经进行了查询调用以检索所有相应的数据库对象,从而破坏了分页的主要目标之一(一次检索小块数据)?
Django 中的查询是惰性的,这意味着 Entry.objects.all() 不会带来完整的条目列表,它只是指定 Endless 将显示的结果范围。