Opened 17 years ago

Closed 17 years ago

#6887 closed (invalid)

fixing vote function in mysite/polls/views.py on page 4 of tutorial

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

Description

There is a line of code missing from the vote function defined in mysite/polls/views.py on page 4 of the Tutorial:

Is

{{{ def vote(request, poll_id):

p = get_object_or_404(Poll, pk=poll_id)
try:

... }}}

Should be

{{{ def vote(request, poll_id):

p = get_object_or_404(Poll, pk=poll_id)
return render_to_response('polls/vote.html', {'poll': p})
try:

... }}}

Change History (1)

comment:1 by Karen Tracey <kmtracey@…>, 17 years ago

Resolution: invalid
Status: newclosed

? The formatting is screwy above so maybe I'm missing something, but if vote() had a "return render_to_response" right after looking up the poll the vote would not be recorded. Sending the response is handled in the code after the try: where the vote is set. If an exception is raised when recording the vote, the poll detail page is re-displayed with an error message describing what went wrong. If setting the vote succeeds, a redirect is sent so that the next page displayed is a view of the poll results.

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