将Django Paginator与CouchDB一起使用时出现的问题
我正在尝试将Django的Paginator与CouchDB一起使用。下面的代码将成功地从coach检索文档/记录。然而,问题是它会返回所有记录;不是我想要的每套5英镑 我是在什么地方出错了,还是Django的Paginator与Coach不兼容将Django Paginator与CouchDB一起使用时出现的问题,django,couchdb,Django,Couchdb,我正在尝试将Django的Paginator与CouchDB一起使用。下面的代码将成功地从coach检索文档/记录。然而,问题是它会返回所有记录;不是我想要的每套5英镑 我是在什么地方出错了,还是Django的Paginator与Coach不兼容 def content_queue(request): # Get the current user user = str(request.user) # Filters the CouchDB View Doc "All" by user couc
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)
首先,检查“page.object\u list”真正返回的内容
然后在将内容传递给Paginator之前,尝试将内容转换为列表。。谢谢你的指点。我只是把沙发上的内容转换成一个列表,一切都正常。