我写了这个简单的程序:
@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)
它适用于GET
方法,但它不适用于PUT
。尝试发送put
消息,我可以在浏览器中看到此错误:
Method Not Allowed
The method is not allowed for the requested URL.
put
方法发生了什么?
如果我在程序中的put
处更改post
方法,它将正常工作。
答案 0 :(得分: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>
'''