我想将 extra_context 添加到 Userena 模板中,以便我可以在模板中进行额外的查询:
def users_watching(request, username):
qs = Thing.objects.filter(watchlist__user__username=username)
return list_detail.object_list(
request,
queryset = Thing.objects.all(),
template_name = 'userena/profile_detail.html',
template_object_name = 'watch',
extra_context = {'watch_list':qs},
)
但是,这里没有呈现任何内容:
{% for watch in watch_list %}
Lorem Ipsum
{{ watch.user }}
{% endfor %}
“Lorem Ipsum”没有被渲染,这让我相信它watch_list
根本没有被包括在内。在 python 解释器中执行这个查询会返回值,所以我知道这个查询是有效的。
编辑:
我认为我将其包含在 urls.py 中的方法可能是问题所在:
url(r'^accounts/(?P<username>(?!signout|signup|signin)[\.\w-]+)/$',
userena_views.profile_detail,
users_watching,
name='userena_profile_detail'),
这导致TypeError
:
Traceback:
File "/lib/python2.7/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/lib/python2.7/django/core/urlresolvers.py" in resolve
300. sub_match = pattern.resolve(new_path)
File "/lib/python2.7/django/core/urlresolvers.py" in resolve
207. kwargs.update(self.default_args)
Exception Type: TypeError at /accounts/SomeDude/
Exception Value: 'function' object is not iterable