Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (30 sloc) 1.44 KB
layout title
Sessions with Sub-apps

Sessions with Sub-apps

Other languages: français | ...


This solutions is taken from this post on the mailing list.


In its default behavior, session information can only be shared from within the main application, even if you 'import' the session from other modules. You need to be able to access session information from 'sub applications' but how?


In your (or initialize your session like this:

session = web.session.Session(app, web.session.DiskStore('sessions'),
initializer = {'test': 'woot', 'foo':''})

.. and create a processor via web.loadhook:

def session_hook():
    web.ctx.session = session


.. and now in your 'sub-apps' (like you can access the the session information like this:

print web.ctx.session.test = 'bar'

.. if you want to make sessions avaible in templates you should change session_hook function like this:

def session_hook():
    web.ctx.session = session
    web.template.Template.globals['session'] = session

.. and now you can write in template something like this:

$session.get('logged_in', ''):
    <p>You are $session.username</p>
    <p>You are not logged in</p>