我正在尝试使用Django的Paginator和CouchDB。以下代码将成功从Couch检索文档/记录。但是,问题在于它返回所有记录;不是我想要的每套5件。
我在某个地方犯了错误,还是Django的Paginator与Couch不兼容?
def content_queue(request):
# Get the current user
user = str(request.user)
# Filters the CouchDB View Doc "All" by user
couch_contents = ContentQueue.view("myapp/all", key=user)
# This next section sets up Paginator
ITEMS_PER_PAGE = 5
paginator = Paginator(couch_contents, ITEMS_PER_PAGE)
try:
page_number = int(request.GET['page'])
except (KeyError, ValueError):
page_number = 1
try:
page = paginator.page(page_number)
except InvalidPage:
raise Http404
couch_contents = page.object_list
# Here I pass the variables to the template
variables = Context ({
'couch_contents': couch_contents,
'tag_list': tag_list,
'show_paginator': paginator.num_pages > 1,
'has_prev': page.has_previous(),
'has_next': page.has_next(),
'page': page_number,
'pages': paginator.num_pages,
'next_page': page_number + 1,
'prev_page': page_number -1
})
return render_to_response('content_queue.html', variables)
答案 0 :(得分:1)
首先,检查“page.object_list”真正返回的内容。
然后尝试将couch_contents转换为列表,然后再将其传递给Paginator。