我对我的观点有点问题,因为它在django上返回了一个错误,但我不知道我做错了什么。在我看来,我的代码如下:
from django.views.generic import TemplateView
from django.shortcuts import render
from community.models import Community
class CommunityLanding(TemplateView):
def get_context_data(request):
template_name = 'community/landing.html'
objects = Community.objects.all()
context = {
'object': objects
}
return render(request, template_name, context)
有人能给我指出正确的方向吗?你知道吗
你的代码几乎都是错的。template\u name属性是在类中定义的,而不是在get\u context\u data方法中定义的。get\u context\u data方法只接受一个参数,它是“self”变量,应该只返回上下文。您不需要手动呈现模板,只要定义了模板名称,其他方法就会处理此问题。你知道吗
你应该读更多关于subclassing the generic views
相关问题 更多 >
编程相关推荐