Django extra_context list_detail不存在变量

时间:2013-10-22 18:58:57

标签: python django templates django-queryset

我想将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

0 个答案:

没有答案