diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/3.1.txt | 3 | ||||
| -rw-r--r-- | docs/topics/http/urls.txt | 13 |
2 files changed, 13 insertions, 3 deletions
diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index cdacbd71cd..3def8920cc 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -294,7 +294,8 @@ Tests URLs ~~~~ -* ... +* :ref:`Path converters <registering-custom-path-converters>` can now raise + ``ValueError`` in ``to_url()`` to indicate no match when reversing URLs. Utilities ~~~~~~~~~ diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index ef9d4c007c..efe61d041c 100644 --- a/docs/topics/http/urls.txt +++ b/docs/topics/http/urls.txt @@ -156,7 +156,14 @@ A converter is a class that includes the following: user unless another URL pattern matches. * A ``to_url(self, value)`` method, which handles converting the Python type - into a string to be used in the URL. + into a string to be used in the URL. It should raise ``ValueError`` if it + can't convert the given value. A ``ValueError`` is interpreted as no match + and as a consequence :func:`~django.urls.reverse` will raise + :class:`~django.urls.NoReverseMatch` unless another URL pattern matches. + + .. versionchanged:: 3.1 + + Support for raising ``ValueError`` to indicate no match was added. For example:: @@ -666,7 +673,9 @@ included at all). You may also use the same name for multiple URL patterns if they differ in their arguments. In addition to the URL name, :func:`~django.urls.reverse()` -matches the number of arguments and the names of the keyword arguments. +matches the number of arguments and the names of the keyword arguments. Path +converters can also raise ``ValueError`` to indicate no match, see +:ref:`registering-custom-path-converters` for details. .. _topics-http-defining-url-namespaces: |
