Session in DG3 is a  way to store information set in one page and read in another. It is independent of authentication and can be used for both anonymous users and authenticated user. Each session gets an unique session id that will be the same for as long as the browsers session is open.

Sessions form query and livetext

The simplest way of using session variables in DG3 is to use it in livetext and query strings. You can read this session id by the livetext [{ xdg3.sessionid }]. To use a session, you simply store the value by a query string with the syntax ?xdg3.session.key=value. To read back the value you set, you simply use a livetext with the syntax [{ xdg3.session.key }]. To delete a session when it no longer is needed, you can use a query string in the form ?xdg3.delsession.key=.

[{ xdg3.sessionid }] Returns the session id as a livetext
[{ xdg3.session.key }] Returns the session variable set earlier
?xdg3.session.key=value Sets the session variable to be used later in a livetext
?xdg3.delsession.key= Deletes a session key using query

Session in code

You can also use Python code in custom views to set and read session variables. A session is available in the request object as a dictionary like object.

sess=request.session # get the session store
sessionid = sess.session_key # get the id
sessval = sess.get('mykey')
sess['mykey'] = 'my value' # set a session variable
del sess['mykey'] # deletes a session variable<br>

Code to read from session, set session variables and delete session variables