按照教程我之前做了2次,现在分页不起作用
我收到以下错误
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完成了本教程的所有工作,并完成了本教程的变体。到底是怎么回事?这怎么可能是问题
类型为“方法”的对象没有len()
我之前做过什么?欢迎所有帮助。
最佳答案
all
是一种方法:
queryset_list = Post.objects.all()
关于python - Django分页不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35330786/