diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2022-03-04 12:57:10 +0000 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-03-07 07:57:14 +0100 |
| commit | ae2da5ba652c1a11cd88dcb119744dcecaeb03ee (patch) | |
| tree | 5f79e182a07457487abe2f0108a2f1f65ad8a72d /django/http | |
| parent | 1882f6567df361f52e53b555b2faa677361e128a (diff) | |
Fixed #33562 -- Made HttpResponse.set_cookie() support timedelta for the max_age argument.
Diffstat (limited to 'django/http')
| -rw-r--r-- | django/http/response.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/django/http/response.py b/django/http/response.py index 8ae4719575..59120c8e0d 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -227,6 +227,10 @@ class HttpResponseBase: - a naive ``datetime.datetime`` object in UTC, - an aware ``datetime.datetime`` object in any time zone. If it is a ``datetime.datetime`` object then calculate ``max_age``. + + ``max_age`` can be: + - int/float specifying seconds, + - ``datetime.timedelta`` object. """ self.cookies[key] = value if expires is not None: @@ -246,6 +250,8 @@ class HttpResponseBase: else: self.cookies[key]["expires"] = "" if max_age is not None: + if isinstance(max_age, datetime.timedelta): + max_age = max_age.total_seconds() self.cookies[key]["max-age"] = int(max_age) # IE requires expires, so set it if hasn't been already. if not expires: |
