Picket Session Manager not working in tornado

I want to set a value in a session using the Pycket session manager. Look at the code:

session = SessionManager(self)
session['key'] = 'OMG'

      

After that, in another handler, I used the following code:

session = SessionManager(self)
self.write(str(session['key']))

      

He writes None

! What should I do?

Note: redis works fine in my project and these are my tornado settings:

if __name__ == "__main__":
    tornado.options.parse_command_line()
    app = tornado.web.Application(
        url_patterns,debug=True,
        cookie_secret="61oETz3455545gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
        xsrf_cookies= False,
        template_path=os.path.join(os.path.dirname(__file__), "templates"),
        static_path= os.path.join(os.path.dirname(__file__), "static"),

        **{
                'pycket': {
                    'engine': 'redis',
                    'storage': {
                        'db_sessions': 10,
                        'db_notifications': 11,
                        'max_connections': 2 ** 31,
                        },
                    'cookies': {
                        'expires_days': 120,
                        # 'domain' : SharedConnections.SiteNameUrl[SharedConnections.SiteNameUrl.index(".")+1,-1],
                        'domain' : 'domain.com',

                        },
                    },
                }
    )

      

+3


source to share


1 answer


use this way

session.set('key', 'OMG')

      



I suggest using pycket as follows

import tornado.web
from pycket.session import SessionMixin
from pycket.notification import NotificationMixin


class BaseHandler(tornado.web.RequestHandler, SessionMixin, NotificationMixin):
    def __init__(self, application, request, **kwargs):
        super(BaseHandler, self).__init__(application, request, **kwargs)


class IndexHandler(BaseHandler):
    def get(self, *args, **kwargs):
        self.session.set('key', 'value')
        p = self.session.get('key')
        self.render('index.html')

      

+2


source