Ticket #8092: request.__getitem__.patch
File request.__getitem__.patch, 1.6 KB (added by , 16 years ago) |
---|
-
django/http/__init__.py
39 39 (pformat(self.GET), pformat(self.POST), pformat(self.COOKIES), 40 40 pformat(self.META)) 41 41 42 def __getitem__(self, key):43 for d in (self.POST, self.GET):44 if key in d:45 return d[key]46 raise KeyError, "%s not found in either POST or GET" % key47 48 def has_key(self, key):49 return key in self.GET or key in self.POST50 51 __contains__ = has_key52 53 42 def get_host(self): 54 43 """Returns the HTTP host using the environment or request headers.""" 55 44 # We try three options, in order of decreasing preference. -
docs/request_response.txt
170 170 Methods 171 171 ------- 172 172 173 ``__getitem__(key)``174 Returns the GET/POST value for the given key, checking POST first, then175 GET. Raises ``KeyError`` if the key doesn't exist.176 177 This lets you use dictionary-accessing syntax on an ``HttpRequest``178 instance. Example: ``request["foo"]`` would return ``True`` if either179 ``request.POST`` or ``request.GET`` had a ``"foo"`` key.180 181 ``has_key()``182 Returns ``True`` or ``False``, designating whether ``request.GET`` or183 ``request.POST`` has the given key.184 185 173 ``get_host()`` 186 174 **New in Django development version** 187 175