Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added documentation for reverse() (based on a patch from Simon Greenh…

…ill) and

another cross-reference to permalink(). Fixed #4103.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5362 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a4e3581dfc8e16970014d1ecf5b9d6af7e4f46f4 1 parent 43dd1c6
@malcolmt malcolmt authored
Showing with 34 additions and 0 deletions.
  1. +34 −0 docs/url_dispatch.txt
View
34 docs/url_dispatch.txt
@@ -551,3 +551,37 @@ not restricted to valid Python names.
Putting a prefix on your URL names, perhaps derived from the application
name, will decrease the chances of collision. We recommend something like
``myapp-comment`` instead of ``comment``.
+
+Utility methods
+===============
+
+reverse()
+---------
+
+If you need to use something similar to the ``{% url %}`` template tag in your
+code, Django provides the ``django.core.urlresolvers.reverse()``. The
+``reverse()`` function has the following signature::
+
+ reverse(viewname, urlconf=None, args=None, kwargs=None)
+
+The view name is either the function name or the `URL pattern name`_).
+Normally you will not need to worry about the ``urlconf`` parameter and will
+only pass in the positional and keyword arguments to use in the url matching.
+For example::
+
+ from django.core.urlresolvers import reverse
+
+ def myview(request):
+ return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
+
+.. _URL pattern name: `Naming URL patterns`_
+
+permalink()
+-----------
+
+The ``permalink()`` decorator is useful for writing short methods that return
+a full URL path. For example, a model's ``get_absolute_url()`` method. Refer
+to the `model API documentation`_ for more information about ``permalink()``.
+
+.. _model API documentation: ../model-api/#the-permalink-decorator
+
Please sign in to comment.
Something went wrong with that request. Please try again.