Code

#18946 closed Uncategorized (fixed)

Possible error in vote function

Reported by: mr_rjharris@… Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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):
        # Redisplay the poll voting form.

I tried to generate an exception by opening a blank page in the browser and entering an url such as

http://localhost:8000/polls/1/vote/

and received the following response

NameError at /polls/1/vote/

global name 'Choice' is not defined.  etc.

I modified the except line to

except KeyError:

and the code worked as expected, opening the url http://localhost:8000/polls/1/vote/

Attachments (0)

Change History (2)

comment:1 Changed 19 months ago by mr_rjharris@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 19 months ago by anonymous

  • Resolution set to fixed
  • Status changed from new to closed

Sorry, I just failed to add Choice to the list of polls.models

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.