Maybe try to bind (once) such a method to your templates ? session = lambda : web.ctx.session
Each call to session() would dynamically load the current web.ctx.session On Fri, May 20, 2011 at 9:31 PM, Joshua Higgins <[email protected]>wrote: > Okay so it seems to be something to do with the loadhook in the sub app... > > It works if I render the template in the sub app like this: > > render = web.template.render('templates/', > > base='layout', > > globals={'session': web.ctx.session}, > > ) > > > But that means I'd have to do that for *every* one.... Has anyone else run > into this problem? > > > Josh. > > On 20 May 2011 20:06, Anthony L. Awtrey <[email protected]> wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> On 05/20/2011 02:58 PM, Joshua Higgins wrote: >> > I've got sessions with sub-apps working, but now I want to access the >> > session data in a sub-app's template. >> > >> > In the main application.py I have: >> > >> > def session_hook(): >> > >> > web.ctx.session = session >> > >> > web.template.Template.globals['session'] = session >> > >> > >> > app.add_processor(web.loadhook(session_hook)) >> > >> > >> > But I'm getting global name 'session' is not defined when using $session >> > in a sub-app template. >> > >> > >> > I tried adding a load hook into my sub app like so: >> > >> > >> > def session_hook(): >> > >> > session = web.ctx.session >> > >> > web.template.Template.globals['session'] = session >> > >> > app_stations.add_processor(web.loadhook(session_hook)) >> > >> > >> > But it doesn't work and I'm struggling. Am I on the right track? >> >> >> In my little example app, I'm doing it like this: >> >> https://github.com/DaGoodBoy/webpy-example/blob/master/index.py >> >> # Start the session and stick it in a database >> sdb = sessiondb.SessionDB( app ) >> >> # This is required for the sub-apps and templates to >> # access to the shared session data >> def session_hook(): >> web.ctx.session = sdb.get_session() >> web.template.Template.globals['session'] = sdb.get_session() >> >> # This adds the session data as an app processor >> app.add_processor( web.loadhook( session_hook ) ) >> >> It looks like you aren't calling get_session() when you assign it; you >> are just putting the session variable in there. Is that correct? >> >> Tony >> - -- >> Anthony Awtrey >> http://www.awtrey.com/ >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.4.11 (GNU/Linux) >> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ >> >> iQEcBAEBAgAGBQJN1ruiAAoJEAPVzrg8Oofbs30IANJIlrvw4hUydKs3vP4+0zaH >> htj08k9ZVGC40rGlLwuT1sv9XxkJ2NP4IS9wopofV8pPD85iewD1u/om3pr/dFUw >> nWNaxoAav7CpdYnATBXnlWF0ztVRDn///CCwiAb3TJSXSxFHYpCsPva5yWHma8aE >> jYXP8WRXLEvHXjQsQ3dGuB9p1G/e2N/WfPv0QKwI/nNYPR+r/T3WtIuF5/xy3gN3 >> hcZHD5DmAP64KwVCyeDx6uVc0eQyGi0F960TyXdoOWax5U2mUrQly+fL6/1OONC4 >> XOjUjeSCPyG2AZ+LjZSWUIyrlDx7iEu9tLSMmD9DsROYeubBKCusag7w8mq8JpE= >> =+gtT >> -----END PGP SIGNATURE----- >> > > > > -- > joshua higgins > > >>>>>>------ > > -- > You received this message because you are subscribed to the Google Groups > "web.py" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/webpy?hl=en. > -- You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/webpy?hl=en.
