Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 24 lines (14 sloc) 0.587 kb
be451bc xrfang edit
xrfang authored
1 ---
2 layout: default
3 title: Using session in template
4 ---
5
6 # Using session in template
7
ee2a8cb Add link to french translation
nux authored
8 Other languages: [français](/../cookbook/session_in_template/fr) | ...
f473cdf xrfang Initial version
xrfang authored
9
ee2a8cb Add link to french translation
nux authored
10 ##Problem:
11
12 I want to use session in template (e.g. get session.username to display)
13
14 ##Solution:
f473cdf xrfang Initial version
xrfang authored
15
16 In your application code:
17
18 render = web.template.render('templates', globals={'context': session})
19
20 In the template:
21
22 <span>You are logged in as <b>$context.username</b></span>
23
24 You can literally use any valid python variable names, like the _context_ used above. I would prefer just use 'session' in real applications.
Something went wrong with that request. Please try again.