from http.cookies import SimpleCookie cookie = SimpleCookie() cookie['username'] = 'John Doe' cookie['age'] = 25
from http.cookies import SimpleCookie cookie = SimpleCookie() cookie['username'] = 'John Doe' cookie['username']['expires'] = 7200 # expires in 7200 seconds (2 hours)
from http.cookies import SimpleCookie # The following code section would retrieve cookies from the incoming request cookie_string = 'In this example, a cookie string is retrieved from an incoming request and used to create a SimpleCookie object. This cookie object is then sent back to the client as a response header. The SimpleCookie module is part of Python's standard library, specifically the http.cookies module.' cookie = SimpleCookie(cookie_string) # The following code section would send cookies to the client response_headers = [('Set-Cookie', str(cookie)), ('Content-type', 'text/html')]