CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=39850d2e574155a2283bc32e; HttpOnly; Path=/; Secure
set-cookie: trac_session=d3f0850552ae8989ca6ad567; expires=Wed, 22 Oct 2025 01:57:39 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Thu, 24 Jul 2025 01:57:39 GMT
x-served-by: cache-fra-eddf8230170-FRA, cache-bom-vanm7210020-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753322259.284099,VS0,VE294
vary: Accept-Encoding
CookBookViews – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
Example views
This is an example to break up long lists into several pages. It uses one url (get) variable "?offset=xxx"
def item_index(request): offset = int(request.GET.get("offset", 0)) item_count = items.get_count() limit=50 if (offset + limit) < (item_count - 1): new_offset = offset + limit else: limit= (item_count - offset) new_offset = False latest_item_list = items.get_list(order_by=['-date'], offset=offset, limit=limit) return render_to_response('item/list', { 'latest_item_list': latest_item_list, 'item_count': item_count, 'from': offset + 1, 'to': limit, 'offset': new_offset, })
This is the template I use. It’s a very simple one, only displaying a row counter and a date column:
{% if latest_item_list %} <p> {% if item_count %} There {% ifequal item_count "1" %}is{% endifequal %} {% ifnotequal item_count "1" %}are{% endifnotequal %} {{ item_count }} item{{ item_count|pluralize }}. {% else %} No itemcount provided to the template {% endif %} You are looking at {{ from }} to {{ to }}. </p> <table width="100%"> <tr> <th style="text-align:left;">#</th><th style="text-align:left;">Date</th> </tr> {% for item in latest_item_list %} <tr> <td>{{ forloop.counter }}</td> <td>{{ item.date }}</td> </tr> {% endfor %} </table> {% else %} <p>There are no items available.</p> {% endif %} <p> {% if offset %} <a href="?offset={{ offset }}">next</a> {% else %} End of list. {% endif %} </p>
Last modified
19 years ago
Last modified on Mar 10, 2006, 5:00:12 AM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.