Set up multiple session handlers on python webapp2

大城市里の小女人 提交于 2019-12-08 12:03:55

问题


I'm writing a simple web application in google appengine and python. In this application I need to handle two types of sessions: the "long term session" that stores information about users, current page ecc, with long max_age parameter and the "short term session" with max_age about 20 minutes that keep an access token for the autentication via API.

I have implemented the following BaseHandler:

import webapp2
from webapp2_extras import sessions

class 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>

the problem is that all sessions have max_age=20*60 seconds (and not only the sessions accessible by self.session_auth).. How should I solve this?

thanks


回答1:


Try setting your config params:

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)


来源:https://stackoverflow.com/questions/39335513/set-up-multiple-session-handlers-on-python-webapp2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!