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 %}