change tornado cookie secret while running

Viewed 28

I need to change tornado cookie secret while its running. all the sample's define the secret code before start tornado server and I want to change cookie secret while my server running because I want to my server ignore all the cookie data saved before (expire cookie not do the job) and save new one's

1 Answers

Every RequestHandler class has a copy of the main settings under self.application.settings.

You can modify the settings before setting the cookies:

class MyHandler(web.RequestHandler):
    def change_cookie_secret(self):
        self.application.settings['cookie_secret'] = '<new secret>'

Call self.change_cookie_secret() method before you create cookies.

Related