shortened 404 try/catch on detail

This commit is contained in:
Josh Flatt 2025-11-22 20:43:28 -06:00
parent e4ebde5944
commit c717a8e25c

View File

@ -1,5 +1,5 @@
from django.shortcuts import render
from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from django.template import loader
from .models import Question
@ -14,10 +14,7 @@ def index(request):
def detail(request, question_id):
try:
question = Question.objects.get(pk=question_id)
except Question.DoesNotExist:
raise Http404("Question does not exist")
question = get_object_or_404(Question, pk=question_id)
return render(request, "polls/detail.html", {"question": question})