Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8202351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:09:08+00:00 2026-06-07T07:09:08+00:00

i am learning django from official django tutorial. and i am getting this error

  • 0

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

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 error message screen :

**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 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/init.py
in get_prep_value, line 537

and here is 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'),

)

and here is project/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'),

)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:09:10+00:00Added an answer on June 7, 2026 at 7:09 am

    You’ll receive this error when you’re trying to cast a string to an integer, but the string doesn’t really contain any digits:

    i.e.

    number = int(string)
    

    From your code, there are three places where I see the use and probable cast of an integer. When p=get_object_or_404(Poll, pk=poll_id) we’re making an assumption that you’ve correctly passed in an integer as poll_id. Could you post the urlpattern you’re using associated with this view and an example URL?

    You also are making an assumption that request.POST['choice'] will be an integer and can be cast as such. You aren’t catching an exception related to this, so you’ll want to check what the value of this entry is. I would add in a few other checks for this part:

    if request.method=="POST":
        choice = request.POST.get('choice', None)
        if choice is not None:
            selected_choice = p.choice_set.get(pk=choice)
    ...
    

    These two stand out the most.

    Please post your urlpattern and more of the error message you were getting (such as which specific line is throwing your exception).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started learning django. I created a form from django models. On
I'm learning python and Django coming from PHP. This is all really exciting, and
So I'm learning Django (1, 3, 1, 'final', 0) through this resource: http://www.djangobook.com/en/2.0/chapter05/ I
Been stuck on this for ages. Currently learning Django and done some bits on
Since a few weeks I am learning Python and Django. Up to this point
So, Im learning django from djangobook.com and a bit confused about the project skeleton
Since I started learning Django framework I came across several applications that switched from
I'm trying to learn Django. I'm completely green so far. I'm learning from not
I am learning Django and I tried to create a template like this: >>>
In the process of learning Django and Python. I can't make sense of this.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.