Basics about passing variable to the user's session

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Basics about passing variable to the user's session

Germán Rimoldi

Hi Guys! 


I need help passing variable to the user's session and calling this from a different function: Could you help me out with this?


First, I would like ot "set" a variable on the user's session.


@cherrypy.expose
def setter(self):
    email = "[hidden email]"
    cherrypy.session["email"] = email
    return "Variable passed to session"        


Second, I would like to call that variable from the session on a different function.

@cherrypy.expose
def getter(self):
    return cherrypy.session.get("email")        

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Basics about passing variable to the user's session

Germán Rimoldi
We have opened this issue on Stackoverflow, please your help! :)

http://stackoverflow.com/questions/41539543/how-to-store-cherrypy-session-in-a-variable

On Sunday, January 8, 2017 at 7:42:28 PM UTC-3, Germán Rimoldi wrote:

Hi Guys! 


I need help passing variable to the user's session and calling this from a different function: Could you help me out with this?


First, I would like ot "set" a variable on the user's session.


@cherrypy.expose
def setter(self):
    email = "[hidden email]"
    cherrypy.session["email"] = email
    return "Variable passed to session"        


Second, I would like to call that variable from the session on a different function.

@cherrypy.expose
def getter(self):
    return cherrypy.session.get("email")        

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Basics about passing variable to the user's session

Stephan Semerad
In reply to this post by Germán Rimoldi
cherrypy.session['email'] = 'email'

email = cherrypy.session['email']

or here the working example

import cherrypy

class app():

    @cherrypy.expose
    def set_session(self, email = "[hidden email]"):
        cherrypy.session["email"] = email
        return email

    @cherrypy.expose
    def get_session(self):
        return cherrypy.session['email']

cherrypy.quickstart(app(), "/", {
    "/": {
        "tools.sessions.on": True,
        }
    })



On Sunday, January 8, 2017 at 11:42:28 PM UTC+1, Germán Rimoldi wrote:

Hi Guys! 


I need help passing variable to the user's session and calling this from a different function: Could you help me out with this?


First, I would like ot "set" a variable on the user's session.


@cherrypy.expose
def setter(self):
    email = "<a href="javascript:" target="_blank" gdf-obfuscated-mailto="FTs3a1CvFAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">em...@..."
    cherrypy.session["email"] = email
    return "Variable passed to session"        


Second, I would like to call that variable from the session on a different function.

@cherrypy.expose
def getter(self):
    return cherrypy.session.get("email")        

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.