diff options
| author | jburns6789 <117755326+jburns6789@users.noreply.github.com> | 2024-11-20 17:18:05 -0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-12-02 11:11:05 +0100 |
| commit | b8f9f625a19298379dbc16d916694702cd038f52 (patch) | |
| tree | 1fffe64f0fff8696b93c392a31be71f35896ef9e /docs | |
| parent | 49761ac99a064236b4280ca55f97a896913109cd (diff) | |
Fixed #35915 -- Clarified the empty list case in QueryDict.__getitem__() docs.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/request-response.txt | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 26fcb5fa08..632e222998 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -554,12 +554,21 @@ a subclass of dictionary. Exceptions are outlined here: .. method:: QueryDict.__getitem__(key) - Returns the value for the given key. If the key has more than one value, - it returns the last value. Raises + Returns the last value for the given key; or an empty list (``[]``) if the + key exists but has no values. Raises ``django.utils.datastructures.MultiValueDictKeyError`` if the key does not exist. (This is a subclass of Python's standard :exc:`KeyError`, so you can stick to catching ``KeyError``.) + .. code-block:: pycon + + >>> q = QueryDict("a=1&a=2&a=3", mutable=True) + >>> q.__getitem__("a") + '3' + >>> q.__setitem__("b", []) + >>> q.__getitem__("b") + [] + .. method:: QueryDict.__setitem__(key, value) Sets the given key to ``[value]`` (a list whose single element is |
