我一直想弄明白为什么我总是得到 *“object of type 'method' has no len()",它将我引导到这一行。请帮助我一直在它在过去的3天,我真的想拉我的头发了。
from django.core.paginator import Paginator
def index(request):
allPosts = Post.objects.all().order_by("id").reverse
#paginator
paginator = Paginator(allPosts, 10)
page_number = request.GET.get('page')
*posts_of_page = paginator.get_page(page_number)*
return render(request, "network/index.html", {
"allPosts" : allPosts,
"posts_of_page" : posts_of_page,
})
1条答案
按热度按时间fhg3lkii1#
看起来你忘了在你的env中添加“()”
所以allPosts是反向方法而不是QuerySet
要解决您的问题,您应该修改此行,使其看起来像这样: