Skip to content

Commit

Permalink
Fixed #35915 -- Clarified the empty list case in QueryDict.__getitem_…
Browse files Browse the repository at this point in the history
…_() docs.
  • Loading branch information
jburns6789 authored and sarahboyce committed Dec 2, 2024
1 parent 49761ac commit b8f9f62
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions docs/ref/request-response.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b8f9f62

Please sign in to comment.