Code

Opened 5 years ago

Closed 5 years ago

#10914 closed (duplicate)

The chapter "Write a simple form" produces code with bad Choice.DoesNotExist handling

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

Description

If you code the “polls/detail.html” template and the "mysite/polls/views.py" vote() function as in the tutorial, after voting without choosing an option, a DoesNotExist exception is raised and the poll voting form is redisplayed with a "You didn't select a choice." message. The problem is that you cannot try to vote a second time, because the redisplayed page is not "polls/1/" but "polls/1/vote/".

To reproduce:

  • Complete tutorial 1 to 4 (for Django 1.0.2)
  • go to "http://localhost:8000/polls/1/"
  • Click vote without selecting a Choice
  • The page will be polls/1/vote/, not polls/1/ again
  • Try to vote (or not, just click again vote)


It fails because it tries to access "polls/1/vote/vote/"

Attachments (0)

Change History (2)

comment:1 Changed 5 years ago by tobami

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

A possible solution would be to modify the form in poll_detail.html.

Replacing
<form action="vote/" method="post">

with
<form action="/polls/{{ object.id }}/vote/" method="post">

solves the problem, but it strikes me as a bit "hacky".

Is there another, cleaner way to solve it?

comment:2 Changed 5 years ago by kmtracey

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

#10801 already reported this.

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.