烧瓶中方法不允许错误

发布于 2021-01-29 14:10:40

尝试提交请求时出现此错误。

Method Not Allowed

The method is not allowed for the requested URL.

这是我的烧瓶代码。

@app.route("/")
def hello():
  return render_template("index.html")

@app.route("/", methods=['POST','GET'])
def get_form():
  query = request.form["search"]
  print query

还有我的index.html

<body>

<div id="wrap">
  <form action="/" autocomplete="on" method="POST">
    <input id="search" name="search" type="text" placeholder="How are you feeling?">
     <input id="search_submit" value="Send" type="submit">
  </form>
</div>

  <script src="js/index.js"></script>

</body>

编辑..我完整的烧瓶代码:

from flask import  Flask,request,session,redirect,render_template,url_for
import flask
print flask.__version__
app = Flask(__name__)

@app.route("/")
def entry():
    return render_template("index.html")

@app.route("/data", methods=['POST'])
def entry_post():
    query = request.form["search"]
    print query
    return render_template("index.html")


if __name__ == "__main__":
    app.run()
关注者
0
被浏览
166
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    您正在发布到该entry()函数,而您的entry_post()函数侦听 另一条路线 ;它被注册为仅收听/data,而不是/

    @app.route("/data", methods=['POST'])
    def entry_post():
    

    /路由不接受POST,默认情况下仅接受GETHEAD并且OPTIONS被允许。

    相应地调整表格:

    <form action="/data" autocomplete="on" method="POST">
    

    考虑到瓶并 不会 重新加载源,除非你将调试

    app.run(debug=True)
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看