Make a custom method of Python paging yourself

Source: Internet
Author: User

The program is distributed as follows: 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6F/B6/wKioL1WmIZuSNdkTAADCpCqFtQo421.jpg "title= "Distribute. png" alt= "wkiol1wmizusndktaadcpcqftqo421.jpg"/>

The database is probably as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6F/B9/wKiom1WmITbjCx1lAAMlcFbo4kQ531.jpg "title=" Qq29.png "alt=" Wkiom1wmitbjcx1laamlcfbo4kq531.jpg "/>

The code in test.py is as follows:

#coding =utf-8  #m   #m \__author__ =  ' Administrator ' import mysqldb  #mfrom   Django.shortcuts import render_to_responseimport jsondef getdata (Request):     conn = mysqldb.connect (             host= ' 192.168.8.176 ',             port  = 3306,            user =  ' Chenhuachao ',            passwd =  ' 123 ',             db =  ' MyBlog ',      )     cur=conn.cursor () #    curr_page=request. Get.get ("page", "") #    curr_page=request. get["page"]    curr_page=int (Request. Get.get ("page", "1"))  &NBsp;  a=int (curr_page) *3    sql= "select * from blogs_blog  limit  "+str (a)  +", 3 "    cur.execute (SQL)     infors= Cur.fetchall ()     results=[]    for infor in infors:         results.append ({' id ': infor[0], ' title ': infor[1], ' author ': infor[ 2], ' content ': [3], ' post_date ': infor[4]})     count_sql= "Select  count (*)  from  blogs_blog "    cur.execute (count_sql)     count_sql=cur.fetchall ( )     count=count_sql[0][0]#   count1 = json.dumps (Count_sql) #    count2=json.loads (count) #   c=int (count1)     cur.close ()     conn.close ()     print count    if  Count % 3 ==0:        num_pages=count /3  #总共的页码     else:         num_pages=count/3+1  #不解释     last_page =int (num_pages) -1  #最后页     int_curr_page=curr_page  #获取url中的页码      if int_curr_page == 0: #判断是否有前一页         has_ Previous=false    else:        has_previous=true     if int_curr_page == int (num_pages): #判断是否有下一页          has_next=False    else:         has_next=True    previous_page_number=int_curr_page -1  #当前页的前一页      nex_page_number=int_curr_page+1  #当前页的后一页     return render_to_ Response (' test.html ', locals ()) 

The definition in the URL:

Urlpatterns = Patterns (', # Examples: # URL (r ' ^$ ', ' pagenation.views.home ', name= ' home '), # URL (r ' ^pagenation/', Include (' Pagenation.foo.urls '), # uncomment the Admin/doc line below to enable admin Documentation:url (R ' ^admin/d Oc/', include (' Django.contrib.admindocs.urls ')), # Uncomment the next line to enable the Admin:url (R ' ^admin/', incl Ude (admin.site.urls)), url (r ' ^test/', GetData),)

The front-end code is as follows: (with Bootstrap, everyone knows)

<! Doctype html>

Specific effects:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6F/B6/wKioL1WmIliAeAucAAIVVRj9Hfg305.jpg "title=" Qq20150715165727.png "alt=" Wkiol1wmiliaeaucaaivvrj9hfg305.jpg "/>

This article is from the "people on the Run" blog, please be sure to keep this source http://leizhu.blog.51cto.com/3758740/1674992

Make a custom method of Python paging yourself

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.