class AboutView(ListView):
template_name = 'index.html'
model = Product
def get_queryset(self):
object_list = self.model.objects.all()
return object_list
def get(request, self):
new_list = object_list
return new_list.order_to(-'price')发布于 2021-05-27 19:38:06
我不知道你的目的,我想使用self.get_queryset()。更多细节:https://www.django-rest-framework.org/api-guide/generic-views/
发布于 2021-05-27 19:47:34
我认为这就是你想要做的:
class AboutView(ListView):
template_name = 'index.html'
model = Product
def get_queryset(self):
object_list = self.model.objects.all()
return object_list
def get(request, self):
new_list = self.get_queryset()
return new_list.order_to(-'price')您不能以尝试的方式访问object_list,而应该从get_queryset方法中获取它。
https://stackoverflow.com/questions/67721240
复制相似问题