Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4391615f35
Fetching contributors…

Cannot retrieve contributors at this time

24 lines (14 sloc) 0.587 kb
layout title
default
Using session in template

Using session in template

Other languages: français | ...

Problem:

I want to use session in template (e.g. get session.username to display)

Solution:

In your application code:

render = web.template.render('templates', globals={'context': session})

In the template:

<span>You are logged in as <b>$context.username</b></span>

You can literally use any valid python variable names, like the context used above. I would prefer just use 'session' in real applications.

Jump to Line
Something went wrong with that request. Please try again.