当我在视图函数中添加“ POST”作为方法时,不允许使用该方法 [英] Method is NOT allowed when i add 'POST' as a method in a view function

查看:101
本文介绍了当我在视图函数中添加“ POST”作为方法时,不允许使用该方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我所有的视图函数中,如果我使用 methods = ['POST'],例如:

In all of my view functions if i 'methods=['POST'] for example:

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

我收到错误:

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

为什么Bottle给我这个错误消息?

Why Bottle gives me this error message?

推荐答案

我猜想在尝试获取视图(GET)时会出错。那是您只允许POST的结果。

I'd guess you get error when trying to get the view (GET). And that is result of your only allowing POST.

您应该拥有

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

或单独的处理程序

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

更新:您复制的示例中似乎有一个错字。 方法应该是方法。

Update: looks like there was a typo in your example that I copied over. 'methods' should be 'method'.

Update2:以下是一个有效的示例:

Update2: Below is a working example:

from bottle import Bottle, run

app = Bottle()

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

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

这篇关于当我在视图函数中添加“ POST”作为方法时,不允许使用该方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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