【问题标题】:django page object is not iterable with pagination example [closed]django 页面对象不可通过分页示例进行迭代[关闭]
【发布时间】:2012-12-20 18:32:49
【问题描述】:

按照这个例子,

Pagination example

我尝试将它与我的一个模型一起使用。

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


【解决方案1】:

您的脚本中有一个错字:people = pagination.page('page') 应该是 people = pagination.page(page)。错误消息中的线索是它期待一个 Page 对象,而无论它得到什么似乎都不像一个。

【讨论】:

    猜你喜欢
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-04
    • 1970-01-01
    • 2011-10-04
    相关资源
    最近更新 更多