0

Is there a function like the get_object_or_404 to not display a 404 error? I have this in my views and I would like to display the page regardless if it finds posts:

tag = get_object_or_404(Keyword, slug=tag)
Droadpc
  • 79
  • 7

1 Answers1

1

No, I think django doesn't have it is because django shouldn't assume what's the default value if the query is not found. Do this:

try:
    tag = Keyword.objects.get(slug=tag)
except Keyword.DoesNotExist:
    tag = None
Shang Wang
  • 24,909
  • 20
  • 73
  • 94