-
-
Save ii0/a75c68db3e8e1aa25296fdd3a10950c9 to your computer and use it in GitHub Desktop.
Tornado - POST Request Handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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