【问题标题】:Setting the 'Expires' cookie with Google Appengine使用 Google Appengine 设置“过期”cookie
【发布时间】:2013-11-29 21:48:05
【问题描述】:

我正在学习 Udacity 的使用 Google Appengine 和 Python 的 Web 开发课程。

我想将 cookie 设置为过期,例如设置后 29 天。我如何做到这一点?

我假设它是这样的:

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

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

【问题讨论】:

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


    【解决方案1】:

    您不必手动添加 Set-Cookie 标头,而是可以这样做:

    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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 1970-01-01
      相关资源
      最近更新 更多