Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tornado - XSRF
import tornado.ioloop
import tornado.web
class Page(tornado.web.RequestHandler):
def get(self):
self.render('xsrfform.html')
def post(self):
name = self.get_argument("name")
self.write('Helo ' + name)
application = tornado.web.Application([
(r"/page", Page),
],
debug=True,
xsrf_cookies=True,
cookie_secret="61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo="
)
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
<html>
<title>
Login
</title>
<body>
<form action="/page" method="post">
{% module xsrf_form_html() %}
Username: <input type="text" name="name"/>
<input type="submit" name="login" value="Login"/>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment