【发布时间】:2012-07-11 14:46:06
【问题描述】:
我的应用程序的模板标签代码为上下文变量中缺少的键 (page) 引发 KeyError。在我的模板中,我不使用 context.variableKeyName 引用上下文变量,我只是引用 variableKeyName(例如{% if is_paginated %})。在我的模板中,我可以毫无例外地引用密钥page。
我应该如何将上下文及其所需的键放入我的模板标签中?
以下是详细信息:
我正在使用 django-profiles 返回一些配置文件的列表:
url(r'^profiles/$', 'profiles.views.profile_list',
kwargs={ 'paginate_by':10 },
name='profiles_profile_detail'),
在这里调用这段代码: https://bitbucket.org/ubernostrum/django-profiles..
在我的模板中,我在调用模板标签之前测试{% if is_paginated %}:
{% if is_paginated %}{% load paginator %}{% paginator 3 %}{% endif %}
(我使用的模板标签灵感来自 http://www.tummy.com/.../django-pagination/ 为 django 1.3 http://djangosnippets.org/snippets/2680/ 更新)
但这会导致“分页”的 KeyError。
【问题讨论】:
标签: python django django-templates