def do_GET(self):
# Default message if we don't know a name.
message = "I don't know you yet!"
# Look for a cookie in the request.
if 'cookie' in self.headers:
try:
# Extract and decode the cookie.
c = cookies.SimpleCookie(self.headers['cookie'])
name = c['yourname'].value
# Craft a message, escaping any HTML special chars in name.
message = "Hey there, " + html_escape(name)
except (KeyError, cookies.CookieError) as e:
message = "I'm not sure who you are!"
print(e)
# First, send a 200 OK response.
self.send_response(200)
# Then send headers.
self.send_header('Content-type', 'text/html; charset=utf-8')
self.end_headers()
# Send the form with the message in it.
mesg = form.format(message)
self.wfile.write(mesg.encode())
评论列表
文章目录