名称错误上下文未在基于 class 的视图中定义
Name error context not defined in class based view
我对此很困惑,但这似乎是我的问题。我在此处收到上下文的名称错误:
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)
是定义吗?
@WillemVanOnsem,您完全正确,是 SVCode 和 django 的混合导致了问题。出于某种原因,django 对模板中的注释并不完全满意,并且卡在一段注释掉的代码上,我删除了它,一切正常 运行。
现在已解决
我对此很困惑,但这似乎是我的问题。我在此处收到上下文的名称错误:
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)
是定义吗?
@WillemVanOnsem,您完全正确,是 SVCode 和 django 的混合导致了问题。出于某种原因,django 对模板中的注释并不完全满意,并且卡在一段注释掉的代码上,我删除了它,一切正常 运行。
现在已解决