码迷,mamicode.com
首页 > 其他好文 > 详细

django-pagination分页

时间:2015-10-07 15:56:19      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

1. 将该APP安装至Django项目中。(settings.py)  

INSTALLED_APPS = (
       # ...
       ‘pagination‘,
)

2. 在Django项目的middleware中安装此APP:(请修改settings.py)

MIDDLEWARE_CLASSES = (
       # ...
       ‘pagination.middleware.PaginationMiddleware‘,
)

3. 添加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‘,
)
技术分享

4.导入tag并在你的模板(template)页面上,对你想要分页的列表变量(object_list)进行分页

{% load pagination_tags %}
{% 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))

django-pagination分页

标签:

原文地址:http://www.cnblogs.com/kiddy/p/4858675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!