Skip to main content
Django Output Prediction Hard +35 XP

get_object_or_404

What happens when the object isn't found?

DjangoRead-only
post = get_object_or_404(Post, pk=pk)

What is the output?

Show answer and explanation

Answer: Returns HTTP 404 response

get_object_or_404 is a shortcut that raises Http404 (returning a 404 response) if no matching object exists.

Hint: The name tells you what happens.

What this challenge tests

Output Prediction in Django: shortcuts, views.

Related challenges