Thanks, this seems the best solution:

def mytoken():

 if not session.has_key('mytoken'):

  ran_str = ''.join(random.choice(string.ascii_uppercase +
string.digits) for x in range (8))

  session.mytoken=ran_str

return session.mytoken

---
In template:

custom variable: $mytoken()

----

On Jun 21, 11:35 am, 常剑 <[email protected]> wrote:
> http://webpy.org/cookbook/sessions_with_subapp
> maybe that is what you need.
>
> 2011/6/20 digistam <[email protected]>
>
>
>
>
>
>
>
> > Hi,
> > I have read the information on webpy.org about Web.py and session
> > variables.
> > At the moment I'm using the standard session variables (ip, session
> > id), using this:
>
> > session = web.session.Session(app, web.session.DiskStore('sessions'))
> > render = web.template.render('templates', globals={'context':
> > session})
>
> > In my template, I use this:
> > <p>session id: $context.session_id</p>
> > <p>ip address: $context.ip</p>
>
> > so far, so good.
>
> > But, I wonder if it's possible to add a custom session variable. Let's
> > say I need to have a session variable containing a random number. I
> > have tried to use codes like:
>
> > web.config.session_parameters['my_own_parameter'] = 'some_string'
>
> > but this doesn't work and I can't retrieve it in my template. Many
> > times the result is a 500 server error.
> > I can't find in the web.py documentation about custom session
> > variables.
>
> > Please let me know if it's possible to set and retrieve custom
> > sessions vars or parameters. If so, how.
>
> > Thanks in advance !
>
> > Mark
>
> > --
> > 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.

Reply via email to