Ticket #2329: Paginate.rst
| File Paginate.rst, 1.1 KB (added by catherinedevlin, 3 years ago) |
|---|
Pagination
Pagination breaks up the display of large numbers of records into more reasonably-sized pages. TurboGears' @paginate() decorator makes this easy to add to a page. Its use is documented in the docstring of the paginate function in tg/decorators.py; here is a simplistic usage sample.
In your controller method (i.e., root.py)
import string
from tg.decorators import paginate
from tg import tmpl_context
class RootController(BaseController):
@expose(template="myproject.templates.alphabet")
@paginate('lowercase_letters', items_per_page=5) # default is 10
def alphabet(self):
lowercase_letters = list(string.letters)[:26]
return dict(lowercase_letters=lowercase_letters,
tmpl_context=tmpl_context)
In alphabet.html
<p>The English alphabet consists of the following letters.</p>
Page: ${tmpl_context.paginators.lowercase_letters.pager()}
<ul py:for="letter in lowercase_letters">
<li>
<span py:content="letter">A letter</span>
</li>
</ul>