1
我有TemplateView的家庭和一个网站的事件组织者的页面。现在我想包括与接下来的三个事件的两个模板中像这样的列表模板:在django中包含泛型视图 - 如何正确使用它?
{% include "next-events.html"%}
由于这个模板应该包含在这两个页面,我想大概只能在接下来的事件写一个ListView和包括它在我家中的意见。
class NextEventsView(ListView):
""" a preview of the next events """
queryset = Event.objects.filter(date__gte=datetime.date.today()).order_by('date')[:3]
context_object_name = 'next_events'
class HomePageView(TemplateView, NextEventsView):
template_name = "home/home.html"
class AboutPageView(TemplateView, NextEventsView):
template_name = "home/about.html"
但我还没有完全理解ListView的通用视图是如何得到它的object_list的。如果我有这样的,我得到以下错误:
AttributeError: 'HomePageView' object has no attribute 'object_list'
这可以通过添加object_list中的主页被解决,但不可能是正确的解决方案。
有人可以解释一下,如何做到这样一个正确的方式?
提前致谢!
谢谢你! – setchock