diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/urlresolvers.txt | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/docs/ref/urlresolvers.txt b/docs/ref/urlresolvers.txt index b335d1fc39..3c3be76e75 100644 --- a/docs/ref/urlresolvers.txt +++ b/docs/ref/urlresolvers.txt @@ -13,7 +13,8 @@ your code, Django provides the following function: .. function:: reverse(viewname, urlconf=None, args=None, kwargs=None, current_app=None) ``viewname`` can be a :ref:`URL pattern name <naming-url-patterns>` or the -callable view object. For example, given the following ``url``:: +callable view object used in the URLconf. For example, given the following +``url``:: from news import views @@ -79,6 +80,26 @@ use for reversing. By default, the root URLconf for the current thread is used. Applying further encoding (such as :func:`urllib.parse.quote`) to the output of ``reverse()`` may produce undesirable results. +.. admonition:: Reversing class-based views by view object + + The view object can also be the result of calling + :meth:`~django.views.generic.base.View.as_view` if the same view object is + used in the URLConf. Following the original example, the view object could + be defined as: + + .. code-block:: python + :caption: ``news/views.py`` + + from django.views import View + + + class ArchiveView(View): ... + + + archive = ArchiveView.as_view() + + However, remember that namespaced views cannot be reversed by view object. + ``reverse_lazy()`` ================== |
