class documentation

class MultiValueDict(dict):

Known subclasses: django.http.QueryDict

View In Hierarchy

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.
def __copy__(self):
overridden in django.http.QueryDict

Undocumented

def __deepcopy__(self, memo):
overridden in django.http.QueryDict

Undocumented

def __getitem__(self, key):
Return the last data value for this key, or [] if it's an empty list; raise KeyError if not found.
def __getstate__(self):

Undocumented

def __init__(self, key_to_list_mapping=()):
overridden in django.http.QueryDict

Undocumented

def __repr__(self):

Undocumented

def __setitem__(self, key, value):
overridden in django.http.QueryDict

Undocumented

def __setstate__(self, obj_dict):

Undocumented

def _getlist(self, key, default=None, force_list=False):

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.

def appendlist(self, key, value):
overridden in django.http.QueryDict
Append an item to the internal list associated with key.
def copy(self):
overridden in django.http.QueryDict
Return a shallow copy of this object.
def dict(self):
Return current object as a dict with singular values.
def get(self, key, default=None):
Return the last data value for the passed key. If key doesn't exist or value is an empty list, return default.
def getlist(self, key, default=None):
Return the list of values for the key. If key doesn't exist, return a default value.
def items(self):
Yield (key, value) pairs, where value is the last item in the list associated with the key.
def lists(self):
Yield (key, list) pairs.
def setdefault(self, key, default=None):
overridden in django.http.QueryDict

Undocumented

def setlist(self, key, list_):
overridden in django.http.QueryDict

Undocumented

def setlistdefault(self, key, default_list=None):
overridden in django.http.QueryDict

Undocumented

def update(self, *args, **kwargs):
Extend rather than replace existing key lists.
def values(self):
Yield the last value on every key list.