Created
December 17, 2017 13:58
-
-
Save solidpple/00125ba22cdd991696df3e118179fcb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) | |
from django.shortcuts import get_object_or_404, render | |
from .models import Question | |
# ... | |
def detail(request, question_id): | |
question = get_object_or_404(Question, pk=question_id) | |
return render(request, 'polls/detail.html', {'question': question}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment