【发布时间】:2012-12-20 18:32:49
【问题描述】:
按照这个例子,
我尝试将它与我的一个模型一起使用。
def index(request):
firstTen = Person.objects.all()
pagination = Paginator(firstTen, 2)
page = request.GET.get('page')
try:
people = pagination.page('page')
except PageNotAnInteger:
people = pagination.page(1)
return render_to_response('index.html', {'people': people},
context_instance=RequestContext(request))
由于某种原因,当我在我的视图中使用它时,我得到了'Page' object is not iterable
{% for result in people %}
{% endfor %}
【问题讨论】:
-
people = pagination.page('page') 应该是 people = pagination.page(page)
-
改变这个会给我另一个关于页面不存在的错误,int() 参数必须是字符串或数字,而不是 'NoneType'
-
没关系,谢谢迈克尔·邓恩。发布您的解决方案,我将接受作为答案
标签: django pagination views