close
Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
- Timestamp:
-
Nov 6, 2009, 11:10:24 AM (15 years ago)
- Author:
-
cmlenz
- Comment:
-
Added session usage example
Legend:
- Unmodified
- Added
- Removed
- Modified
-
v1
|
v2
|
|
9 | 9 | == Usage == |
10 | 10 | |
| 11 | When the session filter is enabled (which is the default), a plain Python `dict` is made available as the [wiki:ApplicationObject#ApplicationContextVariables application context variable] `app.ctxt.session`. It should usually not be necessary to access that dictionary directly, as the `diva.session` module provides a couple of module-level functions to read, write and delete session data. |
| 12 | |
| 13 | For example, a simple request handler accessing the session might look like this: |
| 14 | |
| 15 | {{{ |
| 16 | #!python |
| 17 | from diva import session |
| 18 | from diva.templating import output, render |
| 19 | |
| 20 | @output('test.html') |
| 21 | def test(request, response): |
| 22 | cnt = session.get('counter', 0) + 1 |
| 23 | session.set('counter', cnt) |
| 24 | return render(counter=cnt) |
| 25 | }}} |
| 26 | |
11 | 27 | == API Documentation == |
12 | 28 | |