Django Pagination Paging Notes

Source: Internet
Author: User
Tags install django pip install django

Pip Install Django-pagination

Configure setting

Installed_apps = (' pagination ',) middleware_classes = (' PAGINATION.MI Ddleware. 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,}) 

Template file

puppet_c_s.html (key template code)

 <div class= "Base03" >                                             {% load pagination_ tags %}                                            {% autopaginate puppet_admin 5 %}                                                 <table class= "Table table-bordered" >                                                        <tr>                                                                <td>puppet  Module Path </td>                                                               <td>puppet file.conf</td>                                                                <td>puppet  Master configuration file </td>                                                               <td> puppet master ip</td>                                                        </tr>                                                         {% for foo in puppet_admin %}                                                             <tr>                                                                          <td>{{ foo.puppet_model_path }} </td>                                                                          <td>{{ foo.puppet_files_server_path }}</td>                                                                          <td>{{ foo.puppet_config_path }}</td>                                                                          <td>{{ foo.puppet_server_ip  }}</td>                                                             </tr>                                                         {% endfor %}                                                     </table>                                                {% paginate %}                                         </div>


Key parameters:

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


Django Pagination Paging Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.