Fixed #2503 -- Fixed HttpResponse.delete_cookie() to work properly. It now takes path and domain as optional keyword arguments.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3545 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-08-09 15:40:24 +00:00
parent 2c370e1a08
commit 925c711cf7
2 changed files with 15 additions and 8 deletions

View File

@ -203,11 +203,14 @@ class HttpResponse(object):
if val is not None: if val is not None:
self.cookies[key][var.replace('_', '-')] = val self.cookies[key][var.replace('_', '-')] = val
def delete_cookie(self, key): def delete_cookie(self, key, path='/', domain=None):
try: self.cookies[key] = ''
self.cookies[key]['max_age'] = 0 if path is not None:
except KeyError: self.cookies[key]['path'] = path
pass if domain is not None:
self.cookies[key]['domain'] = path
self.cookies[key]['expires'] = 0
self.cookies[key]['max-age'] = 0
def _get_content(self): def _get_content(self):
content = ''.join(self._iterator) content = ''.join(self._iterator)

View File

@ -380,10 +380,14 @@ Methods
.. _`cookie Morsel`: http://www.python.org/doc/current/lib/morsel-objects.html .. _`cookie Morsel`: http://www.python.org/doc/current/lib/morsel-objects.html
``delete_cookie(key)`` ``delete_cookie(key, path='/', domain=None)``
Deletes the cookie with the given key. Fails silently if the key doesn't Deletes the cookie with the given key. Fails silently if the key doesn't
exist. exist.
The ``path`` and ``domain`` arguments are new in the Django development version.
Due to the way cookies work, ``path`` and ``domain`` should be the same
values you used in ``set_cookie()`` -- otherwise the cookie may not be deleted.
``content`` ``content``
Returns the content as a Python string, encoding it from a Unicode object Returns the content as a Python string, encoding it from a Unicode object
if necessary. Note this is a property, not a method, so use ``r.content`` if necessary. Note this is a property, not a method, so use ``r.content``