We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2c5fbe8 commit b038737Copy full SHA for b038737
mysite/polls/views.py
@@ -1,6 +1,5 @@
1
from django.http import HttpResponse
2
-from django.http import Http404
3
-from django.shortcuts import render
+from django.shortcuts import get_object_or_404, render
4
5
from .models import Question
6
@@ -11,10 +10,7 @@ def index(request):
11
10
return render(request, 'polls/index.html', context)
12
13
def detail(request, question_id):
14
- try:
15
- question = Question.objects.get(pk=question_id)
16
- except Question.DoesNotExist:
17
- raise Http404("Question does not exist")
+ question = get_object_or_404(Question, pk=question_id)
18
return render(request, 'polls/detail.html', {'question': question})
19
20
def results(request, question_id):
0 commit comments