Changeset 5649
- Timestamp:
- 07/11/07 19:33:44 (1 year ago)
- Files:
-
- django/trunk/docs/tutorial04.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/tutorial04.txt
r5401 r5649 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 ) … … 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 212 * We've added a name, ``poll_results``, to the results view so that we have 213 a way to refer to its url later on (see `naming URL patterns`_ for more on 214 named patterns). 215 216 .. _naming URL patterns: http://www.djangoproject.com/documentation/url_dispatch/#naming-url-patterns 211 217 212 218 By default, the ``object_detail`` generic view uses a template called … … 256 262 context instead of ``poll``. 257 263 264 The last thing to do is fix the url handling to account for the use of generic 265 views. In the vote view above we used the ``reverse()`` function to avoid 266 hard-coding our URLs. Now that we've switched to a generic view, we'll need to 267 change the ``reverse()`` call to point back to our new generic view. We can't 268 simply use the view function anymore -- generic views can be (and are) used 269 multiple times -- but we can use the name we've given:: 270 271 return HttpResponseRedirect(reverse('poll_results', args=(p.id,))) 272 258 273 Run the server, and use your new polling app based on generic views. 259 274
