Issue
I just started learning Flask but I meet troubles with the POST method.
Here is my (very simple) Python code :
@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
I successfully can submit my form by clicking on the send button but I a 405 error is returned :
Method Not Allowed The method is not allowed for the requested URL.
It is a pretty simple case, but I cannot understand where is my mistake.
Solution
You gotta add "POST" in the route declaration accepted methods. 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/
Answered By - Anarkopsykotik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.