在使用 django 实现分页问题,采用的是class-based views
.
实例代码如下:
class IndexView(generic.ListView):
template_name = 'blog/index.html'
model = Article
paginate_by = 20
但是每当加入paginate_by
,就会出错,浏览器错误信息为:
EmptyPage at /blog/
That page number is less than 1
Request Method: GET
Request URL: http://localhost:8000/blog/
Django Version: 1.9.5
Exception Type: EmptyPage
Exception Value:
That page number is less than 1
Exception Location: /home/hujianxin/.pyenv/versions/django-web/lib/python3.5/site-packages/django/core/paginator.py in validate_number, line 38
Python Executable: /home/hujianxin/.pyenv/versions/django-web/bin/python
Python Version: 3.5.1
Python Path:
['/home/hujianxin/Programming/personal-site',
'/home/hujianxin/Dropbox/Programming/Spark/spark-1.6.1-bin-hadoop2.6/python',
'/home/hujianxin/Programming/personal-site',
'/home/hujianxin/.pyenv/versions/django-web/lib/python35.zip',
'/home/hujianxin/.pyenv/versions/django-web/lib/python3.5',
'/home/hujianxin/.pyenv/versions/django-web/lib/python3.5/plat-linux',
'/home/hujianxin/.pyenv/versions/django-web/lib/python3.5/lib-dynload',
'/home/hujianxin/.pyenv/versions/anaconda3-2.4.1/envs/django-web/lib/python3.5/site-packages/setuptools-20.7.0-py3.5.egg',
'/home/hujianxin/.pyenv/versions/django-web/lib/python3.5/site-packages']
Server time: Sun, 22 May 2016 05:13:56 +0000
还请有经验的大大帮忙看一下。
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.