Answer the question
In order to leave comments, you need to log in
Show articles related to a specific category?
views.py
class LanguageDetailView(View):
def get_queryset(self):
return Post.objects.filter(to_display=True)
def get(self, request, language_slug=None, slug=None):
if language_slug is not None:
post = self.get_queryset().filter(language__slug=language_slug)
elif slug is not None:
post = self.get_queryset().filter(tags__slug=slug)
else:
post = self.get_queryset()
return render(request, 'blog/language_detail.html', {'post_list': post})
urls.py
urlpatterns = [
path('<slug:language_slug>/', views.LanguageDetailView.as_view(), name='post_list'),
# path('<slug:slug>/', views.TagDetailView.as_view(), name='post_list_tag'),
path('', views.MainView.as_view())
]
{% for post in post_list %}
<a href="{{ post.slug }}">{{ post.title|title }} </a>
<p>{{ post.description }}</p>
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Better learn how to debug than repeat questions. At least put print(post) before return render to understand what's wrong with post, or what error you make before it, django will display a bunch of detailed information for you.
ZY and what for you use View when there is ListView?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question