我遇到了cherrypy.session
的问题,它在localhost
上非常有效,但在127.0.0.1
上却无效。同样在Heroku中,当我设置FileSession
时,它会在找不到会话文件的所有页面上返回错误。否则,会话只能在*.herokuapp.com
上工作,而不能在任何第二级域上工作。如何解决呢? Google很少有关于Cherrypy会话的信息
server.py
cherrypy.log.access_log.propagate = False
conf={
'global':
{
'server.socket_host': "0.0.0.0",
'server.socket_port': int(os.environ.get('PORT', settings.WEBPORT)),
'server.thread_pool': 10
},
'/':
{
'tools.sessions.on': True,
'tools.sessions.timeout': 1440,
'tools.sessions.storage_class': cherrypy.lib.sessions.FileSession,
'tools.sessions.storage_path': os.path.join(os.path.dirname(os.path.abspath(__file__)),".sessions"),
},
"/static":
{
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(os.path.dirname(os.path.abspath(__file__)),"static")
}
}
cherrypy.quickstart(web.Server(),"/",conf)
web.py
class Server(object):
@cherrypy.expose
def index(self,*args,**kwargs):
lang=kwargs.get("lang")
kwargs.pop("lang",None)
if not "lang" in cherrypy.session:
if lang in ["ru","en"]:
cherrypy.session["lang"]=lang
else:
cherrypy.session["lang"]="en"
elif lang in ["ru","en"]:
cherrypy.session["lang"]=lang
lang=cherrypy.session.get("lang")
# templating page there with the 'lang'
p=webProcessor.Task(lang)
return p.index()