Django template tag exception

二次信任 提交于 2019-12-11 21:53:19

问题


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 or just plain stupid :P

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


回答1:


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.



来源:https://stackoverflow.com/questions/2524682/django-template-tag-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!