Tornado POST 405: method not allowed

For some reason, I cannot use post methods in torando.

Even the hello_world example does not work when I change the message.

import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def post(self): self.write("Hello, world") application = tornado.web.Application([ (r"/", MainHandler), ]) if __name__ == "__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start() 

It prohibits method 405. Any suggestions?

+4
source share
3 answers

You still need to get if you want to access the page, because access to the page using a browser request using the get method.

 import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def post(self): self.write("Hello, world") get = post # <-------------- application = tornado.web.Application([ (r"/", MainHandler), ]) if __name__ == "__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start() 
+6
source

Falsetru's answer is a useful hint, and yes, you need the get method. But no, I don't think the get and post method should behave the same. The semantics of these two methods are different. Please see the http specifications http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html and look at Brabster’s answer to this question What is the difference between HTTP-Get and HTTP-POST and why HTTP-POST is weaker from the point security view .

(Sorry, my suggestion should be better than the comment on falsetru's answer, but my reputation does not allow)

+3
source

enter image description here The sample code you provided in your question, Work. Just remember to send POST instead of GET using Curl or Postman, for example. If you point the web browser to a URL, it will try to execute a GET that you did not define.

You might not want to define a GET for the URL. It is perfectly legal to have a POST URL, and Tornado certainly allows you to do this. The POST URL can be a common sending point for forms downloaded from many other locations.

0
source

All Articles