gpt4 book ai didi

python - Django 分页不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 16:57:07 25 4
gpt4 key购买 nike

按照我之前已经完成两次的教程,现在分页不起作用我收到以下错误

TypeError at /posts/
object of type 'method' has no len()
Request Method: GET
Request URL: http://127.0.0.1:8000/posts/
Django Version: 1.9.2
Exception Type: TypeError
Exception Value:
object of type 'method' has no len()
Exception Location: /Users/ray/Desktop/uply/my-server/lib/python3.5/site- packages/django/core/paginator.py in _get_count, line 77
Python Executable: /Users/ray/Desktop/uply/my-server/bin/python
Python Version: 3.5.1
Python Path:
['/Users/ray/Desktop/uply/my-server/src',
'/Users/ray/Desktop/uply/my-server/lib/python35.zip',
'/Users/ray/Desktop/uply/my-server/lib/python3.5',
'/Users/ray/Desktop/uply/my-server/lib/python3.5/plat-darwin',
'/Users/ray/Desktop/uply/my-server/lib/python3.5/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5',
'/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin',
'/Users/ray/Desktop/uply/my-server/lib/python3.5/site-packages']
Server time: Wed, 10 Feb 2016 23:25:54 -0500

这是我的views.py中的代码

def post_list(request):
queryset_list = Post.objects.all
paginator = Paginator(queryset_list, 25)

page = request.GET.get('page')
try:
queryset = paginator.page(page)
except PageNotAnInteger:
queryset = paginator.page(1)
except EmptyPage:
queryset = paginator.page(paginator.num_pages)

template = "posts/post_list.html"
name = "user"
context = {
"object_list": queryset,
"name": name
}
return render(request, template, context)

我在过去两个月中使用相同的最新版本的 django 和 pyhthon 完成了这个教程以及本教程的变体。到底是怎么回事?怎么会出现这个问题 “method”类型的对象没有 len()

我以前什么时候这样做过?欢迎所有帮助。

最佳答案

all 是一个方法:

queryset_list = Post.objects.all()

关于python - Django 分页不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35330786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com