1 <?xml version="1.0" encoding="utf-8" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
7 <title>How to use django-pagination</title>
8 <style type="text/css">
11 :Author: David Goodger
12 :Contact: goodger@users.sourceforge.net
15 :Copyright: This stylesheet has been placed in the public domain.
17 Default cascading style sheet for the HTML output of Docutils.
19 See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
20 customize this style sheet.
23 /* used to remove borders from tables and images */
24 .borderless, table.borderless td, table.borderless th {
27 table.borderless td, table.borderless th {
28 /* Override padding for "table.docutils td" with "! important".
29 The right padding separates the table cells. */
30 padding: 0 0.5em 0 0 ! important }
33 /* Override more specific margin styles with "! important". */
34 margin-top: 0 ! important }
36 .last, .with-subtitle {
37 margin-bottom: 0 ! important }
43 text-decoration: none ;
50 margin-bottom: 0.5em }
52 /* Uncomment (and remove this text!) to get bold-faced definition list terms
60 div.abstract p.topic-title {
64 div.admonition, div.attention, div.caution, div.danger, div.error,
65 div.hint, div.important, div.note, div.tip, div.warning {
67 border: medium outset ;
70 div.admonition p.admonition-title, div.hint p.admonition-title,
71 div.important p.admonition-title, div.note p.admonition-title,
72 div.tip p.admonition-title {
74 font-family: sans-serif }
76 div.attention p.admonition-title, div.caution p.admonition-title,
77 div.danger p.admonition-title, div.error p.admonition-title,
78 div.warning p.admonition-title {
81 font-family: sans-serif }
83 /* Uncomment (and remove this text!) to get reduced vertical space in
85 div.compound .compound-first, div.compound .compound-middle {
86 margin-bottom: 0.5em }
88 div.compound .compound-last, div.compound .compound-middle {
97 div.dedication p.topic-title {
105 div.footer, div.header {
114 div.line-block div.line-block {
121 border: medium outset ;
123 background-color: #ffffee ;
128 div.sidebar p.rubric {
129 font-family: sans-serif ;
132 div.system-messages {
135 div.system-messages h1 {
139 border: medium outset ;
142 div.system-message p.system-message-title {
149 h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
150 h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
168 ol.simple, ul.simple {
172 list-style: decimal }
175 list-style: lower-alpha }
178 list-style: upper-alpha }
181 list-style: lower-roman }
184 list-style: upper-roman }
198 white-space: nowrap }
207 font-family: sans-serif ;
212 font-family: sans-serif ;
224 pre.literal-block, pre.doctest-block {
227 background-color: #eeeeee }
230 font-family: sans-serif ;
231 font-style: oblique }
233 span.classifier-delimiter {
234 font-family: sans-serif ;
238 font-family: sans-serif }
241 white-space: nowrap }
249 span.section-subtitle {
250 /* font-size relative to parent (h1..h6 element) */
254 border-left: solid 1px gray;
262 margin-bottom: 0.5em }
265 border-left: solid 1px black;
268 table.docutils td, table.docutils th,
269 table.docinfo td, table.docinfo th {
270 padding-left: 0.5em ;
271 padding-right: 0.5em ;
272 vertical-align: top }
274 table.docutils th.field-name, table.docinfo th.docinfo-name {
277 white-space: nowrap ;
280 h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
281 h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
285 background-color: #eeeeee }
288 list-style-type: none }
293 <div class="document" id="how-to-use-django-pagination">
294 <h1 class="title">How to use django-pagination</h1>
295 <p><tt class="docutils literal"><span class="pre">django-pagination</span></tt> allows for easy Digg-style pagination without modifying
297 <p>There are really 5 steps to setting it up with your projects (not including
298 installation, which is covered in INSTALL.txt in this same directory.)</p>
300 <li><p class="first">List this application in the <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt> portion of your settings
301 file. Your settings file might look something like:</p>
302 <pre class="literal-block">
309 <li><p class="first">Install the pagination middleware. Your settings file might look something
311 <pre class="literal-block">
312 MIDDLEWARE_CLASSES = (
314 'pagination.middleware.PaginationMiddleware',
318 <li><p class="first">Add this line at the top of your template to load the pagination tags:</p>
320 <p>{% load pagination_tags %}</p>
323 <li><p class="first">Decide on a variable that you would like to paginate, and use the
324 autopaginate tag on that variable before iterating over it. This could
325 take one of two forms (using the canonical <tt class="docutils literal"><span class="pre">object_list</span></tt> as an example
328 <p>{% autopaginate object_list %}</p>
330 <p>This assumes that you would like to have the default 20 results per page.
331 If you would like to specify your own amount of results per page, you can
332 specify that like so:</p>
334 <p>{% autopaginate object_list 10 %}</p>
336 <p>Note that this replaces <tt class="docutils literal"><span class="pre">object_list</span></tt> with the list for the current page, so
337 you can iterate over the <tt class="docutils literal"><span class="pre">object_list</span></tt> like you normally would.</p>
339 <li><p class="first">Now you want to display the current page and the available pages, so
340 somewhere after having used autopaginate, use the paginate inclusion tag:</p>
342 <p>{% paginate %}</p>
344 <p>This does not take any arguments, but does assume that you have already
345 called autopaginate, so make sure to do so first.</p>
348 <p>That's it! You have now paginated <tt class="docutils literal"><span class="pre">object_list</span></tt> and given users of the site
349 a way to navigate between the different pages--all without touching your views.</p>