A subclass of dictionary customized to handle multiple values for the same key.
>>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']}) >>> d['name'] 'Simon' >>> d.getlist('name') ['Adrian', 'Simon'] >>> d.getlist('doesnotexist') [] >>> d.getlist('doesnotexist', ['Adrian', 'Simon']) ['Adrian', 'Simon'] >>> d.get('lastname', 'nonexistent') 'nonexistent' >>> d.setlist('lastname', ['Holovaty', 'Willison'])
This class exists to solve the irritating problem raised by cgi.parse_qs, which returns a list for every key, even though most web forms submit single name-value pairs.
Method | __copy__ |
Undocumented |
Method | __deepcopy__ |
Undocumented |
Method | __getitem__ |
Return the last data value for this key, or [] if it's an empty list; raise KeyError if not found. |
Method | __getstate__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __setitem__ |
Undocumented |
Method | __setstate__ |
Undocumented |
Method | _getlist |
Return a list of values for the key. |
Method | appendlist |
Append an item to the internal list associated with key. |
Method | copy |
Return a shallow copy of this object. |
Method | dict |
Return current object as a dict with singular values. |
Method | get |
Return the last data value for the passed key. If key doesn't exist or value is an empty list, return default . |
Method | getlist |
Return the list of values for the key. If key doesn't exist, return a default value. |
Method | items |
Yield (key, value) pairs, where value is the last item in the list associated with the key. |
Method | lists |
Yield (key, list) pairs. |
Method | setdefault |
Undocumented |
Method | setlist |
Undocumented |
Method | setlistdefault |
Undocumented |
Method | update |
Extend rather than replace existing key lists. |
Method | values |
Yield the last value on every key list. |
Return a list of values for the key.
Used internally to manipulate values list. If force_list is True, return a new copy of values.
django.http.QueryDict
default
.