0

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()已经进行查询调用以检索所有相应的数据库对象,从而破坏了分页的主要目标之一(一次检索小块数据)?

4

1 回答 1

3

Django 中的查询是惰性的,这意味着 Entry.objects.all() 不会带来完整的 Entries 列表,它只是指定 Endless 将显示的结果的范围。

于 2016-01-13T02:37:15.483 回答