python - 使用 Google Appengine 设置 'Expires' cookie

标签 python google-app-engine cookies session-cookies setcookie

我正在学习 Udacity 的使用 Google Appengine 和 Python 进行 Web 开发的类(class)。

我想将 cookie 设置为过期,例如,自设置之日起 29 天。我如何实现这一目标?

我假设它是这样的:

def set_cookie(expire):
    self.response.headers.add_header(
        'Set-Cookie', 
        'Expires=%s; Path=/' % (expire_date))

“过期”值的格式是什么?如何将其到期时间设置为 + 29 天(或分钟、小时、周、月等)?

最佳答案

您不必手动添加 Set-Cookie header ,而是可以执行以下操作:

import datetime

def yourFunction(...):
    expireTime = datetime.datetime.now()  #Check the docs, about adding 29 days, etc.
    self.response.set_cookie('name', 'value', expires=expireTime, path='/', domain='example.com')

关于python - 使用 Google Appengine 设置 'Expires' cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20019074/

相关文章:

python - 为什么 chrome 在错误的子域上设置 cookie?

node.js - 不同客户端 Nodejs 的 session id 相同

python - 'numpy.float6 4' object has no attribute ' 绝对值'

python - 如何在已排序的日期列表中查找缺失的日期?

google-app-engine - 无法使用 goapp 进行部署 - 用户名或密码无效

python - Django Google 应用引擎引用问题

Javascript 移动网站重定向问题

python - 限制wxpython中wxListCtrl的大小

python - pandas.read_csv 中的 dtype 和转换器有什么区别?

java - 使用 Google App Engine (GAE) 防止跨站点脚本编写的最简单方法(框架/库/调用)是什么?