【发布时间】:2020-12-25 00:30:13
【问题描述】:
当我尝试创建基于函数的视图时,它会起作用,显示我的查询集。这是我在下面使用的代码。 在views.py中
def restaurant_listview(request):
template_name ="restaurant/restaurantlist.html"
query_set = Restaurant.objects.all() #all the objects that are stored in da DB
context={"list": query_set}
return render(request,template_name, context)
但是当我尝试将其作为基于类的视图时,它不会显示我的查询集。
在views.py中
`class RestaurantListView(ListView):
queryset = Restaurant.objects.all()
template_name ="restaurant/restaurantlist.html"`
在 urls.py 中
path('restaurants', RestaurantListView.as_view()
我该如何解决这个问题?
【问题讨论】: