Note that there are some explanatory texts on larger screens.

plurals
  1. POinvalid literal for int() with base 10: 'on' Python-Django
    text
    copied!<p>i am learning django from official django tutorial. and i am getting this error when vote something from form. this caused from - probably - vote function under views.py </p> <p>here is my views.py / vote function : </p> <pre><code>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,))) </code></pre> <p>and this is error message screen : </p> <blockquote> <p>**ValueError at /polls/2/vote/</p> <p>invalid literal for int() with base 10: 'on'**</p> <p>Request Method: POST Request URL: 127.0.0.1:8000/polls/2/vote/</p> <p>Django Version: 1.4 Exception Type: ValueError Exception Value: invalid literal for int() with base 10: 'on' Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/models/fields/<strong>init</strong>.py in get_prep_value, line 537</p> </blockquote> <p>and here is my polls/urls.py : </p> <pre><code>from django.conf.urls import patterns, include, url </code></pre> <p>urlpatterns = patterns('polls.views',</p> <pre><code> url(r'^$', 'index'), url(r'^(?P&lt;poll_id&gt;\d+)/$','detail'), url(r'^(?P&lt;poll_id&gt;\d+)/results/$','results'), url(r'^(?P&lt;poll_id&gt;\d+)/vote/$','vote'), </code></pre> <p>)</p> <p>and here is project/urls.py : </p> <pre><code>from django.conf.urls import patterns, include, url </code></pre> <p>urlpatterns = patterns('polls.views',</p> <pre><code> url(r'^$', 'index'), url(r'^(?P&lt;poll_id&gt;\d+)/$','detail'), url(r'^(?P&lt;poll_id&gt;\d+)/results/$','results'), url(r'^(?P&lt;poll_id&gt;\d+)/vote/$','vote'), </code></pre> <p>)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload