Django 1.5迁移问题

时间:2014-07-10 14:36:53

标签: django view migration

我正在尝试将我的视图迁移到django 1.5。我按照在互联网上找到的一个例子,但现在我有一些我自己无法解决的问题......

此视图给出了一个错误:SubListView() received an invalid keyword 'template_object_name'. as_view only accepts arguments that are already attributes of the class

这是观点:

def forum(request, slug):
    try:
        f = Forum.objects.for_groups(request.user.groups.all()).select_related().get(slug=slug)
    except Forum.DoesNotExist:
        raise Http404

    form = CreateThreadForm()
    child_forums = f.child.for_groups(request.user.groups.all())
    callable = SubListView.as_view(
                        queryset=f.thread_set.select_related().all(),
                        paginate_by=FORUM_PAGINATION,
                        template_object_name="thread",
                        template_name='forum/thread_list.html',
                        extra_context = {
                            'forum': f,
                            'child_forums': child_forums,
                            'form': form,
                        })
    return callable(request)

这是相关的SubListView

class SubListView(ListView):
    extra_context = {}
    def get_context_data(self, **kwargs):
        context = super(SubListView, self).get_context_data(**kwargs)
        context.update(self.extra_context)
        return context

有什么想法吗?

1 个答案:

答案 0 :(得分:3)