不能用烧瓶的PUT方法

fao*_*xis 3 python put flask

我写了这个简单的程序:

@app.route('/puttest/', methods=['GET', 'PUT'])
def upload_file():
    if request.method == 'PUT':
        return 'Hello, {}!'.format(request.form['name'])
    else:
        return '''
            <title>Does it work ?</title>
            <h1>PUT test</h1>
            <form action=http://localhost:8887/puttest/ method=put>
                <input type=text name=name>
                <input type=submit value=try>
            </form>

        '''

if __name__ == '__main__':
    app.run('0.0.0.0', 8887)
Run Code Online (Sandbox Code Playgroud)

它适用于GET方法,但它无法使用PUT.尝试发送put消息,我可以在浏览器中看到此错误:

Method Not Allowed

The method is not allowed for the requested URL.
Run Code Online (Sandbox Code Playgroud)

put方法发生了什么?

如果我在程序中的任何地方改变put方法,它将工作正常post.

Nil*_*ils 5

PUT不适用于HTML方法属性.允许的值为:method = get | post

你必须在Webforms中使用POST:

@app.route('/puttest/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
    return 'Hello, {}!'.format(request.form['name'])
else:
    return '''
        <title>Does it work ?</title>
        <h1>PUT test</h1>
        <form action=http://localhost:8887/puttest/ method=post>
            <input type=text name=name>
            <input type=submit value=try>
        </form>
    '''
Run Code Online (Sandbox Code Playgroud)

进一步的信息:在HTML表单HTML标准中使用PUT方法