Django

Code

Changeset 5649

Show
Ignore:
Timestamp:
07/11/07 19:33:44 (1 year ago)
Author:
jacob
Message:

Fixed #4615: corrected reverse URL resolution examples in tutorial 4. Thanks for the patch, simeonf.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/tutorial04.txt

    r5401 r5649  
    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    ) 
     
    209209      from the URL to be called ``"object_id"``, so we've changed ``poll_id`` to 
    210210      ``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 
    211217 
    212218By default, the ``object_detail`` generic view uses a template called 
     
    256262context instead of ``poll``. 
    257263 
     264The last thing to do is fix the url handling to account for the use of generic 
     265views. In the vote view above we used the ``reverse()`` function to avoid 
     266hard-coding our URLs. Now that we've switched to a generic view, we'll need to 
     267change the ``reverse()`` call to point back to our new generic view. We can't 
     268simply use the view function anymore -- generic views can be (and are) used 
     269multiple times -- but we can use the name we've given:: 
     270     
     271    return HttpResponseRedirect(reverse('poll_results', args=(p.id,))) 
     272 
    258273Run the server, and use your new polling app based on generic views. 
    259274