1
在我的博客項目與Django,我想有一個頁面,如category.html顯示所有類別,當我點擊一個類別的鏈接,它顯示的artical類別,就像這樣:http:xxx/category
顯示我所有的類別,並且http:xxx/category/django
顯示所有的django的藝術品django web項目與類別
怎麼辦?
class CategoryView(ListView):
template_name = "index.html"
context_object_name = "article_list"
def get_queryset(self):
article_list = Post.objects.filter(category=self.kwargs['id'])
return article_list
def get_context_data(self, **kwargs):
kwargs['category_list'] = Category.objects.all().order_by('cate_name')
return super(CategoryView, self).get_context_data(**kwargs)