Tsallaka zuwa abun ciki
Justice Tech School

Handling 404

Raise Http404 or use get_object_or_404.

Example
from django.http import Http404
from django.shortcuts import get_object_or_404

def detail(request, pk):
    post = get_object_or_404(Post, pk=pk)
    return HttpResponse(post.title)

Exercise

Shortcut.

(Post, pk=pk)

Quiz Test

What does it raise when missing?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.