Django

Code

Changeset 5362

Show
Ignore:
Timestamp:
05/27/07 07:05:59 (1 year ago)
Author:
mtredinnick
Message:

Added documentation for reverse() (based on a patch from Simon Greenhill) and
another cross-reference to permalink(). Fixed #4103.

Files:

Legend:

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

    r4966 r5362  
    552552    name, will decrease the chances of collision. We recommend something like 
    553553    ``myapp-comment`` instead of ``comment``. 
     554 
     555Utility methods 
     556=============== 
     557 
     558reverse() 
     559--------- 
     560 
     561If you need to use something similar to the ``{% url %}`` template tag in your 
     562code, Django provides the ``django.core.urlresolvers.reverse()``. The 
     563``reverse()`` function has the following signature:: 
     564 
     565    reverse(viewname, urlconf=None, args=None, kwargs=None) 
     566 
     567The view name is either the function name or the `URL pattern name`_). 
     568Normally you will not need to worry about the ``urlconf`` parameter and will 
     569only pass in the positional and keyword arguments to use in the url matching. 
     570For example:: 
     571 
     572    from django.core.urlresolvers import reverse 
     573 
     574    def myview(request): 
     575        return HttpResponseRedirect(reverse('arch-summary', args=[1945])) 
     576 
     577.. _URL pattern name: `Naming URL patterns`_ 
     578 
     579permalink() 
     580----------- 
     581 
     582The ``permalink()`` decorator is useful for writing short methods that return 
     583a full URL path. For example, a model's ``get_absolute_url()`` method. Refer 
     584to the `model API documentation`_ for more information about ``permalink()``. 
     585 
     586.. _model API documentation: ../model-api/#the-permalink-decorator 
     587