python 多人网页会话_在python webapp2上设置多个会话处理程序

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)

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

解决方案

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值