New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #22220, improved reverse() documention #2544

Closed
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+28 −10
Diff settings

Always

Just for now

Fixed #22220, improved reverse() documention

  • Loading branch information...
bendavis78 committed Apr 14, 2014
commit 9585ddfb1592d71877bb5206c10e9b7e8adfc022
View
@@ -12,17 +12,38 @@ your code, Django provides the following function:
.. function:: reverse(viewname, [urlconf=None, args=None, kwargs=None, current_app=None])
``viewname`` is either the function name (either a function reference, or the
string version of the name, if you used that form in ``urlpatterns``) or the
:ref:`URL pattern name <naming-url-patterns>`. Normally, you won't 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::
``viewname`` can be a string containing the Python path to the view object, a
`URL pattern name`_, or the callable view object. For example, given the

This comment has been minimized.

@timgraham

timgraham Apr 16, 2014

Member

I'll merge this, but this appears to be a broken link? should I change it back?

@timgraham

timgraham Apr 16, 2014

Member

I'll merge this, but this appears to be a broken link? should I change it back?

following urlpattern::
url(r'^archive/$', 'news.views.archive', name='news_archive')
you can use any of the following to resolve the URL::
# using the Python path
url = reverse('news.views.archive')
# using the named URL
url = reverse('news_archive')
# passing a callable object
from news import views
url = reverse(views.archive)
If the URL accepts arguments, you may pass them in ``args``. For example::
from django.core.urlresolvers import reverse
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
You can also pass ``kwargs`` instead of ``args``. For example::
>>> reverse('admin:app_list', kwargs={'app_label': 'auth'})
'/admin/auth/'
``args`` and ``kwargs`` cannot be passed to ``reverse()`` at the same time.
If no match can be made, ``reverse()`` raises a
:class:`~django.core.urlresolvers.NoReverseMatch` exception.
@@ -39,12 +60,9 @@ This ``current_app`` argument is used as a hint to resolve application
namespaces into URLs on specific application instances, according to the
:ref:`namespaced URL resolution strategy <topics-http-reversing-url-namespaces>`.
You can use ``kwargs`` instead of ``args``. For example::
The ``urlconf`` argument is the URLconf module containing the url patterns to
use for reversing. By default, the root URLconf for the current thread is used.
>>> reverse('admin:app_list', kwargs={'app_label': 'auth'})
'/admin/auth/'
``args`` and ``kwargs`` cannot be passed to ``reverse()`` at the same time.
.. admonition:: Make sure your views are all correct.
ProTip! Use n and p to navigate between commits in a pull request.