1、安装
sudo python setup.py install
2、将该APP安装至Django项目中。(settings.py)
INSTALLED_APPS = ( # ... ‘pagination‘, )
3、在Django项目的middleware中安装此APP:(请修改settings.py)
MIDDLEWARE_CLASSES = ( # ... ‘pagination.middleware.PaginationMiddleware‘, )
4、添加context上下文(settings.py)
TEMPLATE_CONTEXT_PROCESSORS = ( # ‘django.core.context_processors.auth‘, ‘django.contrib.auth.context_processors.auth‘, ‘django.core.context_processors.debug‘, ‘django.core.context_processors.i18n‘, ‘django.core.context_processors.media‘, ‘django.core.context_processors.request‘, )
5、导入tag
{% load pagination_tags %}
6、在你的模板(template)页面上,对你想要分页的列表变量(object_list)进行分页
{% autopaginate object_list 15 %} {% for object in object_list %} {% object.name %} {% endfor %} {% paginate %}
7、views文件
from django.template import RequestContext
def test(request): contacts = Blog.objects.all() return render_to_response(‘test.html‘,{‘object_list‘:contacts},context_instance=RequestContext(request))