views:

33

answers:

1

I've been using geasessions for a while, been working great. It's simple and fast.

But today I started a new project (GAE v1.3.7) and can't get it to work, get_current_session() just returns None

I've split the code in to a new project that's just using 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, { }))

And in the log it just says None.

The strange part is that the other solutions it still works. (I'm guessing it's due to that the db.Model for Session is already present). Tested both the version I use there and downloaded the latest version (1.04)

I've looked at the source code for gaesessions and it kinda make sense that it returns None:

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

And I can't find anywhere where the Session class is invoked, but then again it could be my laking python skills.

Does anyone use gaesession and know what's happening?

+2  A: 

I think you have missed something in the installation process.

Anyway, if you scroll down the source code you will notice also this part of code that actually valorize the _current_session variable.

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)
systempuntoout
You are absolutely right forgot to add SessionMiddleware in appengine_config!
fredrik