Simple page-Paging steps

Source: Internet
Author: User

URLs

URL (r'^index/(\d*)', Views.index)

Views

 fromDjango.shoutcutsImportRender fromapp impost Models fromAppImportCommon fromDjango.utils.safestringImportMake_safedefIndex (request,page): Page= Common.try_int (page,1) Per_item= 5#Show 5 per pageStart = (page-1) *Per_item End=page-*Per_item Count=models. Host.objects.all (). Count () result=models. Host.objects.all () [Start:end] Sum=-(-count//per_item)#total number of pageslinks=[] First_link='<a href ='/index/{}'> Home <a>'. Format (1) links.append (first_link) Prev_link='<a href ='/index/{}'> Prev <a>'. Format (page-1) links.append (prev_link) forIinchRange (sum):ifpage = = I+1: Link='<a style='clour:red;'href ='/index/{}'>{}<a>'. Format (i+1,i+1)        Else: Link='<a href ='/index/{}'>{}<a>'. Format (i+1,i+1) links.append (link) next_link='<a href ='/index/{}'> Next <a>'. Format (page+1) links.append (next_link) End_link='<a href ='/index/{}'> Last <a>'. Format (sum) links.append (end_link) page= Make_safe ("'. Join (links))#to turn a string into a code that can be displayedRET ={'Count': Count,'Data': result,'page':p Age}returnRender (Request,'index.html', ret)

Common

def Try_int (arg,default):     Try :         = Int (ARG)    expect expection:        = default    return arg
View Code

Simple page-Paging steps

Related Article

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.