Opened 17 years ago

Closed 17 years ago

#4730 closed (duplicate)

Django Tutorial Part 4 - Suggestion

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


The last paragraph in Django Tutorial Part 4 misses a point about generic views. I had problems getting the /polls/ app to work using generic views. The generic views must be made unique in the URLconf ( file.

The "view" ends with a HttpResponseRedirect, which has to send users to a generic view (for poll results). Since both the "details" and "results" pages have the same python function reference name (generic view), couldn't tell them apart. I found two solutions to this issue.

1) Reorder urlpatterns in so that the "results" line is before the "details" one. Then, they will be unique on regular expression, and "results" will match first.

2) Add the 4th "view-name" parameter to urlpatterns tuples to make the "details" and "results" views unique. I chose to enter this:

urlpatterns = patterns(,

(r'$', 'django.views.generic.list_detail.object_list', info_dict),
(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict, 'poll-ballot'),
(r'(?P<object_id>\d+)/results/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, template_name='polls/results.html'), 'poll-results'),
(?P<poll_id>\d+)/vote/$', ''),


Please, change the tutorial near LAST PARAGRAPH to explain all this. This is not an obvious point!

LAST PARAGRAPH (Of Django Tutorial Part 4):

The vote() view is still required. However, it must be modified to match the new templates and context variables. Change the template call from polls/detail.html to polls/poll_detail.html, and pass object in the context instead of poll.

Change History (1)

comment:1 by Chris Beaven, 17 years ago

Resolution: duplicate
Status: newclosed

Thanks for the report. Dupe of #4615 however.

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