Ticket #4615: patch

File patch, 1.9 KB (added by simeonf@…, 17 years ago)

Patch (output from svn diff docs/tutorial04.txt).

  • tutorial04.txt

     
    193193    urlpatterns = patterns('',
    194194        (r'^$', 'django.views.generic.list_detail.object_list', info_dict),
    195195        (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'),
    197197        (r'^(?P<poll_id>\d+)/vote/$', 'mysite.polls.views.vote'),
    198198    )
    199199
     
    209209      from the URL to be called ``"object_id"``, so we've changed ``poll_id`` to
    210210      ``object_id`` for the generic views.
    211211
     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
    212215By default, the ``object_detail`` generic view uses a template called
    213216``<app name>/<model name>_detail.html``. In our case, it'll use the template
    214217``"polls/poll_detail.html"``. Thus, rename your ``polls/detail.html`` template to
     
    255258``polls/detail.html`` to ``polls/poll_detail.html``, and pass ``object`` in the
    256259context instead of ``poll``.
    257260
     261The last thing we have to do is fix the url handling to account for
     262the use of generic views. In the vote view we used ``reverse`` to
     263avoid hard-coding our urls. Change the string 'mysite.polls.detail' in
     264the reverse function to 'poll_results', the name we specified in our
     265url configuration:
     266   
     267    return HttpResponseRedirect(reverse('poll_results', args=(p.id,)))
     268
    258269Run the server, and use your new polling app based on generic views.
    259270
    260271For full details on generic views, see the `generic views documentation`_.
Back to Top