博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
django pagination 分页笔记
阅读量:6657 次
发布时间:2019-06-25

本文共 2484 字,大约阅读时间需要 8 分钟。

hot3.png

pip install django-pagination

配置setting

INSTALLED_APPS = (                    'pagination',                  ) MIDDLEWARE_CLASSES = (               'pagination.middleware.PaginationMiddleware',          )TEMPLATE_CONTEXT_PROCESSORS = (    ###auto page    "django.core.context_processors.auth",)

views.py

from django.core.paginator import Paginator, PageNotAnInteger, EmptyPagedef puppet_admin_c_s(request):    lines = puppet_admin.objects.order_by("-id") ##取总长度    paginator = Paginator(lines, 10)  ##默认10行    page = request.GET.get('page')    try:        show_lines = paginator.page(page)    except PageNotAnInteger:        show_lines = paginator.page(1)    except EmptyPage:        show_lines = paginator.page(paginator.num_pages)    return render_to_response('puppet_c_s.html', RequestContext(request, {'puppet_admin': show_lines,}))

模板文件

puppet_c_s.html(关键模板代码)

 
                                           {% load pagination_tags %}                                          {% autopaginate puppet_admin 5 %}                                              
                                                                                                                 puppet 模块路径                                                            puppet file.conf                                                            puppet 主配置文件                                                            puppet master ip                                                                                                           {% for foo in puppet_admin %}                                                                                                                                {
{ foo.puppet_model_path }}                                                                      {
{ foo.puppet_files_server_path }}                                                                      {
{ foo.puppet_config_path }}                                                                      {
{ foo.puppet_server_ip }}                                                                                                                {% endfor %}                                                                                                {% paginate %}                                      

关键参数:

{% load pagination_tags %}                                       {% autopaginate puppet_admin 5 %}{% paginate %}

转载于:https://my.oschina.net/u/142602/blog/496530

你可能感兴趣的文章
***经验16.5.2总结
查看>>
thunar、nautilus右键添加 "压缩/解压"菜单
查看>>
基于jQuery的waterfall(瀑布流)布局
查看>>
heartheat+drbd高可用存储
查看>>
打包压缩
查看>>
Windows phone开发初体验之-页面导航
查看>>
groovy 闭包的用途
查看>>
前端工程师的进阶之路
查看>>
request
查看>>
Go 语言环境变量设置
查看>>
上海社保已经破产,全国呢?
查看>>
Centos7 配置 sendmail、postfix 端口号25、465
查看>>
ActiveMQ - 初体验,探讨JMS通信模型
查看>>
URL的井号(转自阮一峰)
查看>>
我的友情链接
查看>>
解密FFmpeg播放状态控制内幕
查看>>
我的友情链接
查看>>
90、MPLS基础配置实验
查看>>
51cto博客 存在csrf漏洞
查看>>
我的友情链接
查看>>