下面的代码在服务器中正常工作...虽然来到localhost cookie没有设置请帮我解决这个问题..
def set_cookie(self, key, value='', max_age=None, path='/', domain=None, secure=None, httponly=False, version=None, comment=None): """ Set (add) a cookie for the response """ cookies = BaseCookie() cookies[key] = value for var_name, var_value in [ ('max-age', max_age), ('path', path), ('domain', domain), ('secure', secure), ('HttpOnly', httponly), ('version', version), ('comment', comment), ]: if var_value is not None and var_value is not False: cookies[key][var_name] = str(var_value) if max_age is not None: cookies[key]['expires'] = max_age header_value = cookies[key].output(header='').lstrip() self.response.headers._headers.append(('Set-Cookie', header_value))
答案 0 :(得分:2)
尝试使用
self.response.headers.add_header("Set-Cookie", header_value)
而不是
self.response.headers._headers.append(('Set-Cookie', header_value))
同时尝试使用Cookie.SimpleCookie()
代替Cookie.BaseCookie()