本文介绍了当我在视图函数中添加“ 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 '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”作为方法时,不允许使用该方法
发布评论