How to handle both GET and POST requests in TornadoWeb framework? How to handle both GET and POST requests in TornadoWeb framework? flask flask

How to handle both GET and POST requests in TornadoWeb framework?


You can go with using prepare() method:

Called at the beginning of a request before get/post/etc. Override this method to perform common initialization regardless of the request method.

class MainHandler(tornado.web.RequestHandler):    def prepare(self):        self.render('intro.html')

Hope that helps.


Ok.If you want to handle them together, try this

class MainHandler(tornado.web.RequestHandler):    def get(self):        self.post()    def post(self):        self.render('intro.html')


Try to this:

class MainHandler(tornado.web.RequestHandler):    def get(self):        self.post()    def post(self):        self.render('intro.html')

It should work, if it doesn't add a comment :)

Also you can read some tornado tutorial