ref: http://web2py.com/book/default/chapter/12#Pagination
In following code, there is two problem: 1. The 'next' button always show. And the len(rows) always = 2 2. I don't know how to proper show the {{=rows}} without last row, I want to use the odd row background-color trick. I wrote simliar code in default.py ----------------------------------------- def listall(): if len(request.args): page=int(request.args[0]) else: page=0 items_per_page=2 limitby=(page*items_per_page,(page+1)*items_per_page + 1) words= db().select(db.mytable.ALL, limitby=limitby) cols = [ 'mytable.' + c for c in db.mytable.fields()[1:]] hdrs = dict([(str(c),c.label) for c in db.mytable]) rows =SQLTABLE(words, headers = hdrs, columns=cols, truncate=32) rows['_id'] = 'rows' return dict(rows=rows, page=page, items_per_page=items_per_page) And the view listall.html: ------------------------------- {{extend 'layout.html'}} {{=rows}} page:{{=page}} <br /> len(rows):{{=len(rows)}} <br /> {{if page:}} <a href="{{=URL(r=request, args=[page-1])}}">previous</a> {{pass}} {{if len(rows)>=items_per_page:}} <a href="{{=URL(r=request, args=[page+1])}}">next</a> {{pass}} <script>jQuery("#rows tr:odd").css("background-color", "#bbbbff");</ script>