网站通过id简单分页
1.通过ID分页,要求id是顺序并且连续的:
page = 0 class MainHandler(tornado.web.RequestHandler): def get(self): global page page_pre=self.get_argument("msg_pre",‘0‘) page=page+int(page_pre) if page <= 0:page=1 sql_3="select * from user where id > (‘%s‘-1)*20 order by id asc limit 0,20 "%page res=mysql.cmd(sql_3) mysql.commit() self.render(‘index.html‘,lists=res)
2.建议id顺序的
page = 0 class MainHandler(tornado.web.RequestHandler): def get(self): global page page_pre=self.get_argument("msg_pre",‘0‘) page=page+int(page_pre) if page <= 0: page=0 sql_3="select * from user where id limit %s,10 "%(page*10) res=mysql.cmd(sql_3) mysql.commit() self.render(‘index.html‘,lists=res)
样板html
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <form action="/" method="get"> <button type="submit" name="msg_pre" value=‘-1‘>上一页</button> <button type="submit" name="msg_pre" value=‘1‘>下一页</button> <table> {% for i in lists %} <tr> {% for n in i %} <td>{{n}}</td> {% end %} </tr> {% end %} </table> </form> </body> </html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。