不能对烧瓶使用 PUT 方法
Can't use PUT method with 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)
它适用于 GET
方法,但不适用于 PUT
。尝试发送 put
消息时,我可以在浏览器中看到此错误:
Method Not Allowed
The method is not allowed for the requested URL.
put
方法发生了什么?
如果我在程序的任何地方更改 post
上的 put
方法,它将正常工作。
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>
'''
更多信息:Using PUT method in HTML form and HTML Standard
我写了这个简单的程序:
@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
方法发生了什么?
如果我在程序的任何地方更改 post
上的 put
方法,它将正常工作。
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>
'''
更多信息:Using PUT method in HTML form and HTML Standard