Search code examples
pythoncookiesservertornado

change tornado cookie secret while running


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


Solution

  • 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.