Django

Code

Changeset 8202

Show
Ignore:
Timestamp:
08/03/08 14:55:26 (4 months ago)
Author:
gwilson
Message:

Fixed #8092, #3828 -- Removed dictionary access for request objects so that GET and POST data doesn't "overwrite" request attributes when used in templates (since dictionary lookup is performed before attribute lookup). This is backwards-incompatible if you were using the request object for dictionary access to the combined GET and POST data, but you should use request.REQUEST for that instead.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/http/__init__.py

    r8015 r8202  
    3939            (pformat(self.GET), pformat(self.POST), pformat(self.COOKIES), 
    4040            pformat(self.META)) 
    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" % key 
    47  
    48     def has_key(self, key): 
    49         return key in self.GET or key in self.POST 
    50  
    51     __contains__ = has_key 
    5241 
    5342    def get_host(self): 
  • django/trunk/docs/request_response.txt

    r7814 r8202  
    171171------- 
    172172 
    173 ``__getitem__(key)`` 
    174    Returns the GET/POST value for the given key, checking POST first, then 
    175    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 either 
    179    ``request.POST`` or ``request.GET`` had a ``"foo"`` key. 
    180  
    181 ``has_key()`` 
    182    Returns ``True`` or ``False``, designating whether ``request.GET`` or 
    183    ``request.POST`` has the given key. 
    184  
    185173``get_host()`` 
    186174   **New in Django development version**