I am learning django from the official django tutorial. and I get this error when I vote something from the form. this is probably caused by the voting function under view.py
here is my views.py/vote function:
def vote(request,poll_id):
p=get_object_or_404(Poll, pk=poll_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
return render_to_response('polls/detail.html', {'poll':p,
'error_message' : "didint select anything ",}, context_instance= RequestContext(request))
else:
selected_choice.votes += 1
selected_choice.save()
return HttpResponseRedirect(reverse('polls.views.results', args=(p.id,)))
and this is the error message box:
** ValueError at / polls / 2 / vote /
invalid literal for int () with base 10: 'on' **
Request Method: POST Request URL: 127.0.0.1:8000/polls/2/vote/
Django Version: 1.4 Type of exception: Exception value ValueError: invalid literal for int () with base 10: 'on' Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/models/fields/ init .py in get_prep_value, line 537
and here are my polls /urls.py:
from django.conf.urls import patterns, include, url
urlpatterns = patterns ('polls.views',
url(r'^$', 'index'),
url(r'^(?P<poll_id>\d+)/$','detail'),
url(r'^(?P<poll_id>\d+)/results/$','results'),
url(r'^(?P<poll_id>\d+)/vote/$','vote'),
)
/urls.py:
from django.conf.urls import patterns, include, url
urlpatterns = patterns ('polls.views',
url(r'^$', 'index'),
url(r'^(?P<poll_id>\d+)/$','detail'),
url(r'^(?P<poll_id>\d+)/results/$','results'),
url(r'^(?P<poll_id>\d+)/vote/$','vote'),
)