1. Home
  2. Computer Science MCQs
  3. Django
  4. What does get_object_or_404(Product, pk=5) do if no…

Added 2 Nov 2026

What does get_object_or_404(Product, pk=5) do if no matching product exists?

  1. Raises Http404 (Not Found) Correct answer
  2. Returns the first product instead
  3. Returns None without any error
  4. Creates a new product with pk 5

Correct answer

A. Raises Http404 (Not Found)

14 views

MCQSEXAM

Explanation

This shortcut wraps .get() and converts DoesNotExist into a proper HTTP 404 response, which keeps detail views clean.

Reference

Asked in: Python Developer Interviews, NTS

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Django MCQs

Practise all Django MCQs

Similar MCQs