开发者

Django template tag exception

开发者 https://www.devze.com 2022-12-24 01:59 出处:网络
It looks like this template tag works like a charm for most people: http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/

It looks like this template tag works like a charm for most people:

http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/

For some reason I get this error: Caught an exception while rendering: 'is_paginated'

I use this template tag in my template like so:

{% load digg_paginator %}
{% digg_paginator %}

Where digg_paginator.py is in my app/templatetags folder and the included template context digg_paginator.html is in my app/templates folder. The queryset that needs pagination is called 'destinations'. If i just specify {% digg_paginator %}, how does it know what variable to paginate? I feel I am missing something important here o开发者_运维技巧r just plain stupid :P

Someone please help, or explain to me how this should be done.


If you read the description of that template tag, it says it is built to paginate using the built-in generic views:

Like the PaginatorTag, this tag is a very basic inclusion tag that builds on the variables already set on the context when paginating with the generic object_list view. There are a few additional context variables created...

The is_paginated variable is setup by the generic view (look at the template_context section of the django documentation linked earlier).

Updated

To use that paginator, you will need to modify your view to use the generic view functionality in Django. Since you haven't provided the code for your views or urls I can't give you any concrete suggestions on how to change your code.

If you follow through the Django Tutorial, in part 4 (the last section) they walk you through modifying the simple application that you built in the previous sections to use generic views. The strength of using generic views is that it automatically handles most of the brain dead index() and detail() view code:

These views represent a common case of basic Web development: getting data from the database according to a parameter passed in the URL, loading a template and returning the rendered template. Because this is so common, Django provides a shortcut, called the "generic views" system.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号