Ticket #4615: patch
File patch, 1.9 KB (added by , 18 years ago) |
---|
-
tutorial04.txt
193 193 urlpatterns = patterns('', 194 194 (r'^$', 'django.views.generic.list_detail.object_list', info_dict), 195 195 (r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict), 196 (r'^(?P<object_id>\d+)/results/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, template_name='polls/results.html') ),196 (r'^(?P<object_id>\d+)/results/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, template_name='polls/results.html'), 'poll_results'), 197 197 (r'^(?P<poll_id>\d+)/vote/$', 'mysite.polls.views.vote'), 198 198 ) 199 199 … … 209 209 from the URL to be called ``"object_id"``, so we've changed ``poll_id`` to 210 210 ``object_id`` for the generic views. 211 211 212 * We've added a name ``poll_results`` to the results view so that we 213 have a way to refer to its url later on. 214 212 215 By default, the ``object_detail`` generic view uses a template called 213 216 ``<app name>/<model name>_detail.html``. In our case, it'll use the template 214 217 ``"polls/poll_detail.html"``. Thus, rename your ``polls/detail.html`` template to … … 255 258 ``polls/detail.html`` to ``polls/poll_detail.html``, and pass ``object`` in the 256 259 context instead of ``poll``. 257 260 261 The last thing we have to do is fix the url handling to account for 262 the use of generic views. In the vote view we used ``reverse`` to 263 avoid hard-coding our urls. Change the string 'mysite.polls.detail' in 264 the reverse function to 'poll_results', the name we specified in our 265 url configuration: 266 267 return HttpResponseRedirect(reverse('poll_results', args=(p.id,))) 268 258 269 Run the server, and use your new polling app based on generic views. 259 270 260 271 For full details on generic views, see the `generic views documentation`_.