Opened 8 years ago

Closed 7 years ago

Last modified 5 years ago

#10801 closed (fixed)

tutorial part 4 vote view needs to redirect in the error case

Reported by: bruce@… Owned by: Jacob
Component: Documentation Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


In part 4 of the tutorial the vote view has the following code for the case that no choice was picked:

 return render_to_response('polls/detail.html', {
            'poll': p,
            'error_message': "You didn't select a choice.",

However, the resulting URL is of the form "" rather than what is should be "". So a redirect is needed. I don't know the best way to do that.

Change History (13)

comment:1 Changed 8 years ago by Karen Tracey

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: invalid
Status: newclosed

No, in the case of an error in the submitted data you want to re-display the poll form with the error message. The tutorial code is correct. Please post to django-users if you are having trouble understanding something; the tutorial has gotten plenty of attention and people using it, so it is unlikely to have an error at this point.

comment:2 Changed 8 years ago by anonymous

if you say so... but if you vote on the resulting page you get a 404 error for the URL "". Doesn't seem right to me.

comment:3 in reply to:  2 Changed 8 years ago by Karen Tracey

Resolution: invalid
Status: closedreopened

Replying to anonymous:

if you say so... but if you vote on the resulting page you get a 404 error for the URL "". Doesn't seem right to me.

You might have mentioned that detail in the original report! That actually points to something that was recently changed -- the form action in the template was changed from /polls/{{ }}/vote/ to just vote/ as part of changeset r10371. That changeset fixed a bajillion tickets so I'm not sure yet what problem exactly that it was supposed to address, but it does seem to have introduced a problem in the error path for the view.

comment:4 Changed 8 years ago by Karen Tracey

milestone: 1.1

#9711 was the ticket for which this change was made. I don't know that making the tutorial polls app more pluggable warrants re-writing the view so my initial impression is the #9711 change ought just be reverted.

comment:5 Changed 8 years ago by Malcolm Tredinnick

Owner: changed from nobody to Malcolm Tredinnick
Status: reopenednew

That looks like a typo in the change. Form action should have been ../vote/, which does make things a little simpler (maybe; also a bit trappier in other ways). I'll poke at this today if nobody else gets to it.

comment:6 Changed 8 years ago by Karen Tracey

Sorry, #9771 is the right original ticket number, somehow my mind tends to morph numbers when copying. I'm not sure ../vote/ is going to work either, given per that ticket description the form is displayed on a page with a url such as /polls/123/. I haven't looked in detail at the tutorial though to see if other stuff has changed to make a ../vote/ action work....

comment:7 Changed 8 years ago by Malcolm Tredinnick

Yeah, don't worry ... I'm going to work through the whole tutorial to check it. It's not clear to me that this change is an improvement at all at the moment and since it's the beginner's tutorial, covering every single portable application practice is clearly out of scope in the interests of pragmatism. Reverting the change is definitely still an option for you.

comment:8 Changed 8 years ago by anonymous

Just a suggestion, but maybe the form's action is a good place to introduce {% url %} template tag in the tutorial?

comment:9 Changed 8 years ago by Jacob

Triage Stage: UnreviewedAccepted

comment:10 Changed 7 years ago by Karen Tracey

#10914 reported this again.

comment:11 Changed 7 years ago by Jacob

Owner: changed from Malcolm Tredinnick to Jacob
Status: newassigned

comment:12 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [10973]) Fixed #10801 -- Reverted a portion of [10371]. Practicality beats purity in this case. Thanks to bruce@… for the report. Refs #9771.

comment:13 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top