From 3dc1ede8718056cf107abf06f6f213cbe23374c8 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 23 Sep 2005 01:17:39 +0000 Subject: [PATCH] Fixed #236 -- Added HttpResponse.delete_cookie() method. git-svn-id: http://code.djangoproject.com/svn/django/trunk@668 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/httpwrappers.py | 6 ++++++ docs/request_response.txt | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/django/utils/httpwrappers.py b/django/utils/httpwrappers.py index 107b63d40b..8b50688f66 100644 --- a/django/utils/httpwrappers.py +++ b/django/utils/httpwrappers.py @@ -175,6 +175,12 @@ class HttpResponse: if val is not None: self.cookies[key][var.replace('_', '-')] = val + def delete_cookie(self, key): + try: + self.cookies[key]['max_age'] = 0 + except KeyError: + pass + def get_content_as_string(self, encoding): """ Returns the content as a string, encoding it from a Unicode object if diff --git a/docs/request_response.txt b/docs/request_response.txt index a004b99126..5b01fc3482 100644 --- a/docs/request_response.txt +++ b/docs/request_response.txt @@ -286,6 +286,10 @@ Methods .. _`cookie Morsel`: http://www.python.org/doc/current/lib/morsel-objects.html +``delete_cookie(key)`` + Deletes the cookie with the given key. Fails silently if the key doesn't + exist. + ``get_content_as_string(encoding)`` Returns the content as a Python string, encoding it from a Unicode object if necessary.