summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorClifford Gama <cliffygamy@gmail.com>2024-10-22 14:12:02 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-10-23 15:37:54 +0200
commit4d11ea1ef01eba14b3a48a727f07f723f782fd84 (patch)
tree639f71cfd06d0655ec79d6d32dc0fdc21b340265 /docs
parentbe138f32ed32a4bf3e62305145423285e462c853 (diff)
Fixed #28999 -- Documented how to reverse a class-based view by instance.
Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/urlresolvers.txt23
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()``
==================