#10801 closed (fixed)
tutorial part 4 vote view needs to redirect in the error case
Reported by: | 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: | no | UI/UX: | no |
Description
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 "http://127.0.0.1:8000/polls/1/vote/" rather than what is should be "http://127.0.0.1:8000/polls/1/". So a redirect is needed. I don't know the best way to do that.
Change History (13)
comment:1 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
follow-up: 3 comment:2 by , 16 years ago
if you say so... but if you vote on the resulting page you get a 404 error for the URL "http://127.0.0.1:8000/polls/1/vote/vote/". Doesn't seem right to me.
comment:3 by , 16 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Replying to anonymous:
if you say so... but if you vote on the resulting page you get a 404 error for the URL "http://127.0.0.1:8000/polls/1/vote/vote/". 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/{{ poll.id }}/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 by , 16 years ago
milestone: | → 1.1 |
---|
comment:5 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
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 by , 16 years ago
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 by , 16 years ago
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 by , 16 years ago
Just a suggestion, but maybe the form's action is a good place to introduce {% url %} template tag in the tutorial?
comment:9 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:11 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:12 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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.