1. Problem

A cookie that the user is presenting is no longer valid; you wish to delete it.

2. Solution

Use the expire_cookie() method of the HTTPResponse object.

     request.response.expire_cookie('login_time', path='/')

This causes the cookie's expiration date to be set to a date in the past, causing the cookie to be deleted.

3. Discussion

See CookieSecurity for a discussion of security considerations related to cookies.

Strictly speaking the 'path' argument is optional, but some clients will only delete the cookie if the path argument's value matches the one provided when the cookie is created. Therefore you should always specify it.


CategoryCookbook