Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #567 -- Added HttpRequest.has_key() method. Thanks, wojtek3@bra…

…ndlay.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@711 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8b67f5f829a998c860e107173584dcc4346d1225 1 parent 2d1303b
Adrian Holovaty authored September 27, 2005
3  django/utils/httpwrappers.py
@@ -20,6 +20,9 @@ def __getitem__(self, key):
20 20
                 return d[key]
21 21
         raise KeyError, "%s not found in either POST or GET" % key
22 22
 
  23
+    def has_key(self, key):
  24
+        return self.GET.has_key(key) or self.POST.has_key(key)
  25
+
23 26
     def get_full_path(self):
24 27
         return ''
25 28
 
12  docs/request_response.txt
@@ -110,6 +110,18 @@ All attributes except ``session`` should be considered read-only.
110 110
 Methods
111 111
 -------
112 112
 
  113
+``__getitem__(key)``
  114
+    Returns the GET/POST value for the given key, checking POST first, then
  115
+    GET. Raises ``KeyError`` if the key doesn't exist.
  116
+
  117
+    This lets you use dictionary-accessing syntax on an ``HttpRequest``
  118
+    instance. Example: ``request["foo"]`` would return ``True`` if either
  119
+    ``request.POST`` or ``request.GET`` had a ``"foo"`` key.
  120
+
  121
+``has_key()``
  122
+    Returns ``True`` or ``False``, designating whether ``request.GET`` or
  123
+    ``request.POST`` has the given key.
  124
+
113 125
 ``get_full_path()``
114 126
     Returns the ``path``, plus an appended query string, if applicable.
115 127
 

0 notes on commit 8b67f5f

Please sign in to comment.
Something went wrong with that request. Please try again.