django-pagination分页

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)

django-pagination分页
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,
)
django-pagination分页

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))

 

 

django-pagination分页

上一篇:好玩的命令


下一篇:微信携手“互联网+”行动计划助力发展智慧城市的目标