aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-06-11 19:59:33 -0400
committerBobby <[email protected]>2023-06-11 19:59:33 -0400
commit2be0508590faba7ebb5914ba972f5f3a23332e45 (patch)
tree6d3b02190bddbcc30fb42a0cea964b630632ee00
parentb0d1c9827c53d3d33facf08fc2043f43801ae6fa (diff)
downloadthatcomputerscientist-2be0508590faba7ebb5914ba972f5f3a23332e45.tar.xz
thatcomputerscientist-2be0508590faba7ebb5914ba972f5f3a23332e45.zip
404 Error fix for non-existing tags
-rw-r--r--blog/views.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/blog/views.py b/blog/views.py
index ce04688d..2d2a9ebc 100644
--- a/blog/views.py
+++ b/blog/views.py
@@ -61,7 +61,10 @@ def tags(request):
return render(request, 'blog/tags.html', {'title': 'Tags', 'tags': tags})
def tag_posts(request, tag_slug):
- tag = Tag.objects.get(slug=tag_slug)
+ try:
+ tag = Tag.objects.get(slug=tag_slug)
+ except Tag.DoesNotExist:
+ raise Http404("Tag does not exist")
posts = Post.objects.filter(tags__name__in=[tag.name]).order_by('views')
for post in posts:
post.excerpt = add_excerpt(post)