简体   繁体   English

Flask - POST - 请求的URL不允许使用该方法

[英]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.15000 / 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.

相关问题 请求的 URL 不允许使用该方法:使用 Flask POST 方法 - The method is not allowed for the requested URL: Using Flask POST Method 所请求的URL不允许使用该方法-Flask + HTML - The method is not allowed for the requested URL - Flask + HTML 所请求的URL不允许使用该方法。 在烧瓶 - The method is not allowed for the requested URL. in Flask Python Flask:错误“请求的 URL 不允许使用该方法” - Python Flask: Error "The method is not allowed for the requested URL" 如何修复 Flask 中的“请求的 URL 不允许使用该方法” - How to fix "The method is not allowed for the requested URL" in Flask 不允许的方法 请求的 URL 不允许使用该方法。 在 DELETE 方法烧瓶上 - Method Not Allowed The method is not allowed for the requested URL. on DELETE Method Flask Python、Flask:方法不允许,请求的方法不允许 URL - Python, Flask: Method Not Allowed, The method is not allowed for the requested URL Flask 错误:“方法不允许 请求的 URL 不允许该方法” - Flask Error: “Method Not Allowed The method is not allowed for the requested URL” Flask 错误:“方法不允许 请求的 URL 不允许该方法” - Flask Error: "Method Not Allowed The method is not allowed for the requested URL" Flask 错误:方法不允许 请求的 URL 不允许该方法 - Flask error: Method Not Allowed The method is not allowed for the requested URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM