2010-09-09 82 views
1

我一直在使用geasessions一段时间,一直在努力工作。它简单快捷。今天get_current_session返回无

但我开始了一个新的项目(GAE v1.3.7),不能得到它的工作,get_current_session()刚刚返回None

我在给一个刚刚使用gaesessions一个新的项目拆分代码:

from google.appengine.ext import webapp 
from google.appengine.ext.webapp import util 
from google.appengine.ext.webapp import template 
from gaesessions import get_current_session 
import logging 

class MainHandler(webapp.RequestHandler): 
    def get(self): 
     session = get_current_session() 
     logging.info(session) 
     path = os.path.join(os.path.dirname(__file__), 'index.html') 
     self.response.out.write(template.render(path, { })) 

而在日志中它只是说None

奇怪的部分是,它仍然工作的其他解决方案。 (我猜这是因为db.Model for Session已经存在)。测试了我用那里的版本,并下载最新的版本(1.04)

我已经看过了source code为gaesessions和它有点意义,它返回None:

_current_session = None 
def get_current_session(): 
    """Returns the session associated with the current request.""" 
    return _current_session 

,我不能找到Session类被调用的任何地方,但这又可能是我的Python技巧。

有人使用gaesession并知道发生了什么?

回答

2

我想你错过了installation process中的一些东西。无论如何,如果你向下滚动源代码,你会注意到这部分代码实际上会使_current_session变量变为高度。

def __call__(self, environ, start_response): 
     # initialize a session for the current user 
     global _current_session 
     _current_session = Session(lifetime=self.lifetime, no_datastore=self.no_datastore, cookie_only_threshold=self.cookie_only_thresh, cookie_key=self.cookie_key) 
+0

你绝对正确的忘记了在appengine_config中添加SessionMiddleware! – fredrik 2010-09-09 15:13:33