抛出404异常
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})
return HttpResponse(template.render(context, request))
node1:/django/mysite/polls/templates/polls#cat detail.html
{{ question.id }}
{{ question.question_text }}