Django模板标签异常
看起来这个模板标签对大多数人来说都很有吸引力:
http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/
由于某种原因,我收到此错误:渲染时捕获异常:'is_pagination'
我在模板中使用此模板标记,如下所示:
{% load digg_paginator %}
{% digg_paginator %}
其中 digg_paginator.py 位于我的 app/templatetags 文件夹中,包含的模板上下文 digg_paginator.html 位于我的 app/templates 文件夹中。需要分页的查询集称为“目的地”。如果我只指定 {% digg_paginator %}
,它如何知道要分页的变量?我觉得我在这里遗漏了一些重要的东西,或者只是简单的愚蠢:P
请有人帮忙,或者向我解释一下应该如何做。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您阅读该模板标签的描述,它会说它是为了使用内置的 通用视图:
is_pagination
变量由通用视图设置(查看前面链接的 django 文档的 template_context 部分)。已更新
要使用该分页器,您需要修改视图以使用 Django 中的通用视图功能。由于您尚未提供视图或网址的代码,我无法为您提供有关如何更改代码的任何具体建议。
如果您按照 Django 教程,在 第 4 部分(最后一节)他们将引导您将前面几节中构建的简单应用程序修改为使用通用视图。使用通用视图的优点在于它可以自动处理大部分令人脑残的index()和detail()视图代码:
If you read the description of that template tag, it says it is built to paginate using the built-in generic views:
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: