mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #35915 -- Clarified the empty list case in QueryDict.__getitem__() docs.
This commit is contained in:
parent
49761ac99a
commit
b8f9f625a1
@ -554,12 +554,21 @@ a subclass of dictionary. Exceptions are outlined here:
|
|||||||
|
|
||||||
.. method:: QueryDict.__getitem__(key)
|
.. method:: QueryDict.__getitem__(key)
|
||||||
|
|
||||||
Returns the value for the given key. If the key has more than one value,
|
Returns the last value for the given key; or an empty list (``[]``) if the
|
||||||
it returns the last value. Raises
|
key exists but has no values. Raises
|
||||||
``django.utils.datastructures.MultiValueDictKeyError`` if the key does not
|
``django.utils.datastructures.MultiValueDictKeyError`` if the key does not
|
||||||
exist. (This is a subclass of Python's standard :exc:`KeyError`, so you can
|
exist. (This is a subclass of Python's standard :exc:`KeyError`, so you can
|
||||||
stick to catching ``KeyError``.)
|
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)
|
.. method:: QueryDict.__setitem__(key, value)
|
||||||
|
|
||||||
Sets the given key to ``[value]`` (a list whose single element is
|
Sets the given key to ``[value]`` (a list whose single element is
|
||||||
|
Loading…
Reference in New Issue
Block a user