Но я не могу сообразить, как правильно мне это записать в urls. Подскажите, как правильно все сделать. Мне кажется что я уже сам запутался(
В urls.py
urlpatterns = [ path('', IndexView.as_view(), name='index'), # Главная страница path('blog/', ArticleListView.as_view(), name='article-list'), # Страница блога с перечнем всех статей path('blog/<str:slug>/', CategoryListView.as_view(), name='category-list'), # Страница категории со статьями категории path('<str:slug>/', ArticleDetailView.as_view(), name='article-detail'), # Детальная страница поста # path('<str:slug>/', ArticleByCategoryListView.as_view(), name='article-by-cat') ]
Views.py
class IndexView(ListView): model = Article template_name = 'blog/index.html' context_object_name = 'articles' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['title'] = 'Главная страница' return context class ArticleListView(ListView): model = Article template_name = 'blog/blog.html' context_object_name = 'articles' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['title'] = 'Главная страница' return context class ArticleDetailView(DetailView): model = Article template_name = 'blog/single-post.html' context_object_name = 'article' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['title'] = self.object.title return context class ArticleByCategoryListView(ListView): model = Article template_name = 'blog/blog.html' context_object_name = 'articles' category = None def get_queryset(self): self.category = Category.objects.get(slug=self.kwargs['slug']) queryset = Article.objects.all().filter(category_id=self.category.id) return queryset def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['title'] = f'{self.category.title}' return context class CategoryListView(ListView): model = Category template_name = "blog/category.html"