2
我試圖在Django的分頁程序中使用CouchDB。以下代碼將成功從Couch檢索文檔/記錄。但是,問題是它返回所有記錄;而不是我想要的每組5個。在CouchDB中使用Django分頁程序的問題
我在某個地方犯了什麼錯誤,或者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)
太棒了。感謝指針。我只是將couch_contents轉換成一個列表,一切正常。 – tabdon 2011-05-09 15:31:12