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>
时间: 2024-11-01 20:15:27