Skip to content

Instantly share code, notes, and snippets.

@solidpple
Created December 17, 2017 13:58
Show Gist options
  • Save solidpple/00125ba22cdd991696df3e118179fcb8 to your computer and use it in GitHub Desktop.
Save solidpple/00125ba22cdd991696df3e118179fcb8 to your computer and use it in GitHub Desktop.
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