Fixed #25358 -- Improved variable name for question in tutorial.

This commit is contained in:
Alasdair Nicol 2015-09-06 12:17:59 +01:00 committed by Tim Graham
parent 49eee84245
commit 19f98946f2
2 changed files with 6 additions and 6 deletions

View File

@ -177,7 +177,7 @@ commas, according to publication date:
def index(request): def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5] latest_question_list = Question.objects.order_by('-pub_date')[:5]
output = ', '.join([p.question_text for p in latest_question_list]) output = ', '.join([q.question_text for q in latest_question_list])
return HttpResponse(output) return HttpResponse(output)
# Leave the rest of the views (detail, results, vote) unchanged # Leave the rest of the views (detail, results, vote) unchanged

View File

@ -76,13 +76,13 @@ create a real version. Add the following to ``polls/views.py``:
from .models import Choice, Question from .models import Choice, Question
# ... # ...
def vote(request, question_id): def vote(request, question_id):
p = get_object_or_404(Question, pk=question_id) question = get_object_or_404(Question, pk=question_id)
try: try:
selected_choice = p.choice_set.get(pk=request.POST['choice']) selected_choice = question.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist): except (KeyError, Choice.DoesNotExist):
# Redisplay the question voting form. # Redisplay the question voting form.
return render(request, 'polls/detail.html', { return render(request, 'polls/detail.html', {
'question': p, 'question': question,
'error_message': "You didn't select a choice.", 'error_message': "You didn't select a choice.",
}) })
else: else:
@ -91,7 +91,7 @@ create a real version. Add the following to ``polls/views.py``:
# Always return an HttpResponseRedirect after successfully dealing # Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a # with POST data. This prevents data from being posted twice if a
# user hits the Back button. # user hits the Back button.
return HttpResponseRedirect(reverse('polls:results', args=(p.id,))) return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))
This code includes a few things we haven't covered yet in this tutorial: This code includes a few things we haven't covered yet in this tutorial:
@ -135,7 +135,7 @@ This code includes a few things we haven't covered yet in this tutorial:
'/polls/3/results/' '/polls/3/results/'
where the ``3`` is the value of ``p.id``. This redirected URL will where the ``3`` is the value of ``question.id``. This redirected URL will
then call the ``'results'`` view to display the final page. then call the ``'results'`` view to display the final page.
As mentioned in :doc:`Tutorial 3 </intro/tutorial03>`, ``request`` is an As mentioned in :doc:`Tutorial 3 </intro/tutorial03>`, ``request`` is an