typeidea icon indicating copy to clipboard operation
typeidea copied to clipboard

p162 IndexView部分代码有问题

Open github-yao-tong opened this issue 5 years ago • 1 comments

class IndexView(CommonViewMixin, ListView):

queryset = Post.latest_posts()
paginate_by = 5
context_object_name = 'post_list'
template_name = 'blog/list.html'

这样写会报错: django.core.exceptions.ImproperlyConfigured: IndexView is missing a QuerySet. Define IndexView.model, IndexView.queryset, or override IndexView.get_queryset().

需要加个 model = Post 就好了。

github-yao-tong avatar Apr 22 '20 02:04 github-yao-tong

我照着上面的代码写,没有问题。

MaoningGuan avatar Jun 17 '20 13:06 MaoningGuan