老师报了一个不是整数的错误
PageNotAnInteger at /weibo/user/2/
That page number is not an integer
Request Method:
GET
Request URL:
http://127.0.0.1:8000/weibo/user/2/
Django Version:
1.11.18
Exception Type:
PageNotAnInteger
Exception Value:
That page number is not an integer
Exception Location:
C:\envs\django1.11\lib\site-packages\django\core\paginator.py in validate_number, line 43
Python Executable:
C:\envs\django1.11\Scripts\python.exe
Python Version:
3.8.2
Python Path:
['C:\\Users\\Administrator\\Desktop\\py_learn\\my_project',
'C:\\Users\\Administrator\\Desktop\\py_learn\\my_project',
'C:\\Program Files\\JetBrains\\PyCharm '
'2020.2\\plugins\\python\\helpers\\pycharm_display',
'C:\\envs\\django1.11\\Scripts\\python38.zip',
'd:\\python\\DLLs',
'd:\\python\\lib',
'd:\\python',
'C:\\envs\\django1.11',
'C:\\envs\\django1.11\\lib\\site-packages',
'C:\\Program Files\\JetBrains\\PyCharm '
'2020.2\\plugins\\python\\helpers\\pycharm_matplotlib_backend']
Server time:
Sun, 23 Aug 2020 09:38:28 +0000
from django.core.paginator import Paginator
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
from weibo.models import WeiboUser
def page_user(request,page):
"""对用户进行分页处理"""
page_size = 10 #每一页展示10条记录
user_list = WeiboUser.objects.all() #要分页的数据结果集QuerySet
#分页器对象p
p = Paginator(user_list,page_size)
print("总记录数:",p.count)
print("总页数:",p.num_pages)
print("页码范围:",p.page_range)
#获取每一页的数据
page_data = p.page(page)
print("数据列表:",page_data.object_list)
print("当前第几页:",page_data.number)
print("是否有下一页:",page_data.has_next())
print("是否有上一页:",page_data.has_previous())
return HttpResponse("ok")
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 218 份
- 解答问题 3562 个
本阶段带你用Python开发一个网站,学习主流框架Django+Flask是Python Web开发的第一步,在基础知识上实现积分商城的项目开发,体验真实的项目开发流程,提高解决编程问题和效率的能力。
了解课程


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星