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

本小妞迷上赌 提交于 2020-01-06 14:47:50

问题


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

@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?


回答1:


I'd guess you get error when trying to get the view (GET). And that is result of your only allowing 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:

from bottle import Bottle, run

app = Bottle()

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

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


来源:https://stackoverflow.com/questions/52466285/method-is-not-allowed-when-i-add-post-as-a-method-in-a-view-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!