在我的 ProductList
上课,当我尝试调用 get_context_data
在另一种方法中,我得到一个错误 'ProductList' object has no attribute 'object_list'
def get_context_data(self, **kwargs):
c = super(ProductList, self).get_context_data(**kwargs)
c['category'] = self.category
c['category_menu'] = self.get_category_menu()
c['filters'] = self.filters
c['expanded_filters'] = self.get_expanded_filters()
c['active_filters'] = self.get_active_filters()
c['category_list'] = self.category.get_children().filter(in_lists=True)
c['colors_list'] = self.get_colors_list(c['object_list'])
return c
def get_queryset(self):
data = self.get_context_data()
是什么导致了这个错误?
我怎样才能得到
object_list
在我的第二种方法中?
最佳答案
您可能会在关注 line 时遇到错误在 get_context_data()
父类(super class):
queryset = kwargs.pop('object_list', self.object_list)
get
BaseListView
的方法设置object_list
在 View 上调用 get_queryset
方法:self.object_list = self.get_queryset()
但是,在您的情况下,您正在调用
get_context_data()
在 get_queryset
方法本身和当时 object_list
未在 View 上设置。
关于django - 'ProductList' 对象没有属性 'object_list',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37675704/