diff options
| author | Jack Cushman <jcushman@law.harvard.edu> | 2019-12-21 13:22:18 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-01-09 14:41:41 +0100 |
| commit | eb629f4c028ae220084904db84d633d7b3f0af20 (patch) | |
| tree | d1c16b7756a6aebc89dec4dc5236e00d1e469524 /docs | |
| parent | ceecd0556dc6f013b5b62fedb12453b8ae3b8067 (diff) | |
Fixed #30995 -- Allowed converter.to_url() to raise ValueError to indicate no match.
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: |
