Skip to content

Instantly share code, notes, and snippets.

@ii0
Forked from cjgiridhar/tornadorequesthandler.py
Created July 24, 2018 05:18
Show Gist options
  • Save ii0/a75c68db3e8e1aa25296fdd3a10950c9 to your computer and use it in GitHub Desktop.
Save ii0/a75c68db3e8e1aa25296fdd3a10950c9 to your computer and use it in GitHub Desktop.
Tornado - POST Request Handler
import tornado.ioloop
import tornado.web
class Hello(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
class User(tornado.web.RequestHandler):
def get(self):
form = """<form method="post">
<input type="text" name="username"/>
<input type="text" name="designation"/>
<input type="submit"/>
</form>"""
self.write(form)
def post(self):
username = self.get_argument('username')
designation = self.get_argument('designation')
self.write("Wow " + username + " you're a " + designation)
application = tornado.web.Application([
(r"/", Hello),
(r"/user/", User),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment