뷰는 요청된 질문의 id가 없는 경우 Http 404 예외를 발생시키는 시키도록 함
polls/views.py
from django.http import Http404 from django.shortcuts import render from .models import Question def detail(request, question_id): try: question = Question.objects.get(pk=question_id) except Question.DoesNotExist: raise Http404("Question does not exist") return render(request, 'polls/detail.html', {'question': question})
https://github.com/happydeveloper/django-on/commit/cbd281f8cbf00c78cf455a61eb0d32b34719f0a2
실행 결과