[英]Flask - POST - The method is not allowed for the requested URL
I just started learning Flask but I meet troubles with the POST method. 我刚刚开始学习Flask,但我遇到了POST方法的麻烦。
Here is my (very simple) Python code : 这是我的(非常简单的)Python代码:
@app.route('/test')
def test(methods=["GET","POST"]):
if request.method=='GET':
return('<form action="/test" method="post"><input type="submit" value="Send" /></form>')
elif request.method=='POST':
return "OK this is a post method"
else:
return("ok")
when going to : http://127.0.0.1:5000/test 什么时候去: http : //127.0.0.1 : 5000 / test
I successfully can submit my form by clicking on the send button but I a 405 error is returned : 我成功地可以通过单击发送按钮提交我的表单,但我返回405错误 :
Method Not Allowed The method is not allowed for the requested URL. 方法不允许所请求的URL不允许使用该方法。
It is a pretty simple case, but I cannot understand where is my mistake. 这是一个非常简单的案例,但我无法理解我的错误在哪里。
You gotta add "POST" in the route declaration accepted methods. 你必须在路由声明接受的方法中添加“POST”。 You've put it in the function.
你把它放在了这个功能中。
@app.route('/test', methods=['GET', 'POST'])
def test():
if request.method=='GET':
return('<form action="/test" method="post"><input type="submit" value="Send" /></form>')
elif request.method=='POST':
return "OK this is a post method"
else:
return("ok")
See : http://flask.pocoo.org/docs/0.10/quickstart/ 请参阅: http : //flask.pocoo.org/docs/0.10/quickstart/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.