Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@adrianholovaty adrianholovaty authored
Showing with 15 additions and 0 deletions.
  1. +3 −0  django/utils/httpwrappers.py
  2. +12 −0 docs/request_response.txt
View
3  django/utils/httpwrappers.py
@@ -20,6 +20,9 @@ def __getitem__(self, key):
return d[key]
raise KeyError, "%s not found in either POST or GET" % key
+ def has_key(self, key):
+ return self.GET.has_key(key) or self.POST.has_key(key)
+
def get_full_path(self):
return ''
View
12 docs/request_response.txt
@@ -110,6 +110,18 @@ 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_full_path()``
Returns the ``path``, plus an appended query string, if applicable.
Please sign in to comment.
Something went wrong with that request. Please try again.