老师报了一个不是整数的错误

老师报了一个不是整数的错误

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

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕小猿 2020-08-23 22:05:29

同学你好,老师按修改后的代码运行没有报错,看到同学报错有新的变量,代码中没有这个变量,请同学上传修改后的代码,及访问url截图。方便快速解决问题

http://img1.sycdn.imooc.com//climg/5f4277a409919b0706930524.jpg


好帮手慕小猿 2020-08-23 18:09:51

同学你好,需要将page字段转换为Int类型,如图:

http://img1.sycdn.imooc.com//climg/5f424024096f38c405890420.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~


  • 提问者 Buck_messic #1
    老师又报了这样的错误 ValueError at /weibo/user/2/ invalid literal for int() with base 10: '' Request Method: GET Request URL: http://127.0.0.1:8000/weibo/user/2/ Django Version: 1.11.18 Exception Type: ValueError Exception Value: invalid literal for int() with base 10: '' Exception Location: C:\Users\Administrator\Desktop\py_learn\my_project\weibo\views.py in page_user, line 11 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 10:15:47 +0000
    2020-08-23 18:16:53
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
3.从网页搭建入门Python Web
  • 参与学习           人
  • 提交作业       218    份
  • 解答问题       3562    个

本阶段带你用Python开发一个网站,学习主流框架Django+Flask是Python Web开发的第一步,在基础知识上实现积分商城的项目开发,体验真实的项目开发流程,提高解决编程问题和效率的能力。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师