Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Tornado - Authentication - tornado.web.authenticated
import tornado.ioloop
import tornado.web
class Main(tornado.web.RequestHandler):
def get_current_user(self):
return self.get_secure_cookie("user")
def get(self):
## This work is achieved by decorator @tornado.web.authenticated
#if not self.current_user:
# self.redirect("/login")
# return
username = self.current_user
self.write('Hi there, '+ username)
class Login(Main):
def get(self):
def post(self):
self.set_secure_cookie("user", self.get_argument("username"))
settings = {
application = tornado.web.Application([
(r"/", Main),
(r"/login", Login),
(r"/(style\.css)",tornado.web.StaticFileHandler, {"path": "./css/"}),
], **settings)
if __name__ == "__main__":
Copy link

leopepe commented Dec 1, 2012

Thanks for sharing this, it helped me a lot on understanding how tornado handles and manages cookies and cookie_secret passphrase.

The code of the project is here, if you want to checkout. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment