Emax
Emax

Reputation: 1047

Cherrypy pass local variable between functions under Root()

Please look at the code :

class Root:
    def __init__(self):
        self._Name = None

    def index(self):
        self._Name = getNameFromUser() 
        return mytemplate.render()
    index.exposed = True

    def foo(self):
        myName = self._Name
        //dosomething
        return mytemplate.render( showmyName( myName) )
    foo.exposed = True

if __name__ == '__main__':
    cherrypy.quickstart(Root())

Here is the problem: user 1 , user 2 and user 3 come in, then when site wants to show the name by foo() It returns the most recent user that came into the site I want each user see his/her name.

In Fact I want to have local variable per user HOW to do that ?

Upvotes: 0

Views: 304

Answers (1)

Sean Vieira
Sean Vieira

Reputation: 159915

When you set something on the server object, you are setting it for the application not the user. If you want to store information on a user temporarily, use the sessions interface or (if it is not information that needs to be secured / tamper-proof) in a cookie.

Upvotes: 1

Related Questions