get_object_or_404()

get_object_or_404() method

from django.shortcuts import get_object_or_404

def my_view(request):
    obj = get_object_or_404(MyModel, pk=1)

Calls get() on a given model manager, but it raises Http404 instead of the model’s DoesNotExist exception.

get_object_or_404() — Structure map

Clickable & Draggable!

get_object_or_404() — Related pages: