How to display information that there is no post instead 404 error?
How often does something like this in django?
def post_by_category(request, slug):
category = get_object_or_404(Category, slug=slug)
categories = category.get_descendants(include_self=True)
posts = get_list_or_404(Post, category__in=categories)
return render_to_response("by_category.html",
{'posts': posts, context_instance=RequestContext(request))
By using
posts = get_list_or_404(Post, category__in=categories)you’re explicitly asking it to return a 404 in case there are no posts.Try:
And make sure you print out the error {{ message }} inside
by_category.html.