我正在阅读ListView
的Django源代码:
django/list.py
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
template_name_suffix = '_list'
def get_template_names(self):
try:
names = super().get_template_names()
class ListView(MultipleObjectTemplateResponseMixin, BaseListView):
"""
Render some list of objects, set by `self.model` or `self.queryset`.
`self.queryset` can actually be any iterable of items, not just a queryset.
"""
当我定义ListView
时,template_name
会自动分配
class IndexView(generic.ListView):
pass
我认为MultipleObjectTemplateResponseMixin
中的分配步骤应该是
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
template_name_suffix = '_list'
def get_template_names(self):
try:
names = super().get_template_names()
....
template_name = self.get_template_names()
如何调用get_template_names
而不调用它?
答案 0 :(得分:1)
get_template_names
类的render_to_response
方法中调用 TemplateResponseMixin
,该方法是MultipleObjectTemplateResponseMixin
的超类。