【问题标题】:Set up multiple session handlers on python webapp2在 python webapp2 上设置多个会话处理程序
【发布时间】:2017-01-13 02:45:24
【问题描述】:

我正在用 google appengine 和 python 编写一个简单的网络应用程序。在这个应用程序中,我需要处理两种类型的会话: 存储有关用户信息的“长期会话”,当前页面 ecc,具有长 max_age 参数和具有大约 20 分钟 max_age 的“短期会话”,通过 API 保留访问令牌以进行身份​​验证。

我已经实现了以下 BaseHandler:

导入 webapp2
从 webapp2_extras 导入会话

类 BaseHandler(webapp2.RequestHandler):

def dispatch(self): # Get a session store for this request. self.session_store = sessions.get_store(request=self.request) try: # Dispatch the request. webapp2.RequestHandler.dispatch(self) finally: # Save all sessions. self.session_store.save_sessions(self.response) @webapp2.cached_property def session(self): # Returns a session using the default cookie key. return self.session_store.get_session(backend='memcache') @webapp2.cached_property def session_auth(self): return self.session_store.get_session(backend='memcache', max_age=20*60)<code>

问题在于所有会话的 max_age=20*60 秒(不仅是 self.session_auth 可访问的会话).. 我该如何解决这个问题?

谢谢

【问题讨论】:

    标签: python google-app-engine session webapp2


    【解决方案1】:

    尝试设置你的配置参数:

    config = {}
    config['webapp2_extras.sessions'] = {
        'session_max_age': 100000,   # try None here also, though that is the default
    }
    
    app = webapp2.WSGIApplication([
        ('/', HomeHandler),
    ], debug=True, config=config)
    

    【讨论】:

    • 我尝试设置参数 session_max_age,但这作用于整个会话,而不仅仅是 session_auth..
    • 是的,但是一旦设置了这些,您可以更改 session_auth,其他的应该保持您的默认值。
    猜你喜欢
    • 2011-04-11
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    • 2013-04-23
    相关资源
    最近更新 更多