在基于类的视图中未定义名称错误上下文

时间:2019-07-04 08:48:37

标签: python django dbcontext

对此我感到很困惑,但这确实是我的问题。我在这里遇到上下文名称错误:

class ProjectView(ListView):
    template_name = 'project_portal/home.html'
    queryset = Project.objects.all()

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)  # <-- name error here
        context['update_category'] = UpdateCategory.objects.all()
        context['update'] = Update.objects.all()
        return context

我在这里做错了什么?我以为:

context = super().get_context_data(**kwargs)  

是定义吗?

1 个答案:

答案 0 :(得分:1)

@WillemVanOnsem,您是完全正确的,它是SVCode和django的混合物,引起了问题。出于某种原因,django对模板中的注释并不完全满意,并且卡在注释掉的代码中,我删除了它,一切运行良好。

现在解决了