Commit daa6b38f authored by Gary Wilson Jr's avatar Gary Wilson Jr
Browse files

Fixed #8092, #3828 -- Removed dictionary access for request objects so that...

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.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8202 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 71b2e01e
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -39,17 +39,6 @@ class HttpRequest(object):
            (pformat(self.GET), pformat(self.POST), pformat(self.COOKIES),
            pformat(self.META))

    def __getitem__(self, key):
        for d in (self.POST, self.GET):
            if key in d:
                return d[key]
        raise KeyError, "%s not found in either POST or GET" % key

    def has_key(self, key):
        return key in self.GET or key in self.POST

    __contains__ = has_key

    def get_host(self):
        """Returns the HTTP host using the environment or request headers."""
        # We try three options, in order of decreasing preference.
+0 −12
Original line number Diff line number Diff line
@@ -170,18 +170,6 @@ All attributes except ``session`` should be considered read-only.
Methods
-------

``__getitem__(key)``
   Returns the GET/POST value for the given key, checking POST first, then
   GET. Raises ``KeyError`` if the key doesn't exist.

   This lets you use dictionary-accessing syntax on an ``HttpRequest``
   instance. Example: ``request["foo"]`` would return ``True`` if either
   ``request.POST`` or ``request.GET`` had a ``"foo"`` key.

``has_key()``
   Returns ``True`` or ``False``, designating whether ``request.GET`` or
   ``request.POST`` has the given key.

``get_host()``
   **New in Django development version**

+0 −0

Empty file added.

+1 −0
Original line number Diff line number Diff line
# Models file for tests to run.
+13 −0
Original line number Diff line number Diff line
{% if request %}
Have request
{% else %}
No request
{% endif %}

{% if request.is_secure %}
Secure
{% else %}
Not secure
{% endif %}

{{ request.path }}
Loading