def do_POST(self):
# How long was the post data?
length = int(self.headers.get('Content-length', 0))
# Read and parse the post data
data = self.rfile.read(length).decode()
yourname = parse_qs(data)["yourname"][0]
# Create cookie.
c = cookies.SimpleCookie()
# 1. Set the fields of the cookie.
# Give the cookie a value from the 'yourname' variable,
# a domain (localhost), and a max-age.
# Send a 303 back to the root page, with a cookie!
self.send_response(303) # redirect via GET
self.send_header('Location', '/')
self.send_header('Set-Cookie', c['yourname'].OutputString())
self.end_headers()
评论列表
文章目录