Tornado POST 405:不允许的方法 [英] Tornado POST 405: Method Not Allowed

查看:54
本文介绍了Tornado POST 405:不允许的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我无法在 Tornado 中使用 POST 方法.

For some reason, I am not able to use POST methods in tornado.

当我将 GET 更改为 POST 时,即使 hello_world 示例也不起作用.

Even the hello_world example does not work when I change GET to POST.

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()

它抛出405 method not allowed".有什么建议吗?

It throws "405 method not allowed". Any suggestions?

推荐答案

如果你想访问页面,你仍然需要 get,因为通过 GET 方法.

You still need get if you want access the page, because access the page using browser request with 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()

这篇关于Tornado POST 405:不允许的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆