我正在尝试做这样的事情:
class AboutView(TemplateView):
template_name = 'about.html'
def get_context_data(self, **kwargs):
context = super(AboutView, self).get_context_data(**kwargs)
context['dahl_books'] = Books.objects.filter(author="Dahl')
当我尝试在我的模板中访问dahl_books时:
{% for book in dahl_books %}
dahl_books
在模板上下文中不可用,即使Books QuerySet返回了非零数量的书籍。 ....我在模板或get_context_data
中做错了什么?
答案 0 :(得分:54)
我无法测试,但我打赌你需要
return context
在get_context_data
:)