简体   繁体   English

当我在视图函数中添加“ POST”作为方法时,该方法是不允许的

[英]Method is NOT allowed when i add 'POST' as a method in a view function

In all of my view functions if i 'methods=['POST'] for example: 在我所有的视图函数中,如果我使用'methods = ['POST']例如:

@app.route( '/file', methods=['POST'] )

i receive the error: 我收到错误:

    Error: 405 Method Not Allowed
Sorry, the requested URL 'http://superhost.gr/downloads/file' caused an error:

Why Bottle gives me this error message? 为什么Bottle会给我这个错误信息?

I'd guess you get error when trying to get the view (GET). 我想您在尝试获取视图(GET)时会出错。 And that is result of your only allowing POST. 那是您唯一允许POST的结果。

You should have 你应该有

@app.route( '/file', method=['POST', 'GET'] )

or a separate handler 或单独的处理程序

@app.route( '/file', method=['GET'] )

Update: looks like there was a typo in your example that I copied over. 更新:您复制的示例中似乎有一个错字。 'methods' should be 'method'. “方法”应该是“方法”。

Update2: Below is a working example: Update2:下面是一个有效的示例:

from bottle import Bottle, run

app = Bottle()

@app.route('/file', method=['GET', 'POST'])
def file():
    return "Hello!"

run(app, host='localhost', port=8080)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM