I am trying to do the official Django Tutorial. I just copy/pasted the code from tutorial ( I hope I didnt miss smth ). The view code affecting the result :
#polls/views.py
def results(request, question_id):
response = "You're looking at the results of question %s."
question=get_object_or_404(Question, pk=1)
context={'question':question}
# return HttpResponse(response % question_id)
return render(request,'polls/results.html',context)
def vote(request, question_id):
context={'question_id':question_id,
'error_message': "You didn't select a choice.",}
try:
question=get_object_or_404(Question,pk=question_id)
selected_choice=question.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
return render(request,'polls/detail.html',context)
selected_choice.votes+=1
selected_choice.save()
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))
#polls/templates/results.py
<h1>{{ question.question_text }}</h1>
<ul>
{% for choice in question.choice_set.all %}
<li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }
˓→}</li>
{% endfor %}
</ul>
<a href="{% url 'polls:detail' question.id %}">Vote again?</a>
I got this error
ValueError at /polls/1/vote/
Field ‘id’ expected a number but got ‘{{\r\n˓→choice.id }}’