diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index c1cb6193f5..2779e2ae00 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -81,6 +81,9 @@ class MultiValueDict: def __len__(self): return len(self.data) + def __contains__(self, key): + return self.data.has_key(key) + def get(self, key, default): "Returns the default value if the requested data doesn't exist" try: diff --git a/docs/request_response.txt b/docs/request_response.txt index 85a5e091db..e0b7a01805 100644 --- a/docs/request_response.txt +++ b/docs/request_response.txt @@ -31,11 +31,11 @@ All attributes except ``session`` should be considered read-only. ``GET`` A dictionary-like object containing all given HTTP GET parameters. See the - ``MultiValueDict`` documentation below. + ``QueryDict`` documentation below. ``POST`` A dictionary-like object containing all given HTTP POST parameters. See the - ``MultiValueDict`` documentation below. + ``QueryDict`` documentation below. ``REQUEST`` For convenience, a dictionary-like object that searches ``POST`` first, @@ -150,6 +150,10 @@ directly. * ``__setitem__(key, value)`` -- Sets the given key to ``[value]`` (a Python list whose single element is ``value``). + * ``__contains__(key)`` -- **New in Django development version.*** Returns + ``True`` if the given key exists. This lets you do, e.g., + ``if "foo" in request.GET``. + * ``__len__()`` * ``get(key, default)`` -- Uses the same logic as ``__getitem__()`` above,