from django.contrib.auth.models import User
...
class FruitList(ListView):
model = Fruit
paginate_by = "2"
queryset = Fruit.objects.filter(user=request.user)
context_object_name = "myfruitlist"
template_name = 'myfruit_list.html'
错误:
名称'request'未定义
我该如何解决?
答案 0 :(得分:3)
您必须以这种方式访问它:
def get_queryset(self):
return Fruit.objects.filter(user=self.request.user)
您可以阅读有关此here in docs
的信息