Method not allowed error in bulb

I get this error when I try to send a request.

Method Not Allowed

The method is not allowed for the requested URL.

And here is my flask code.

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

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

And my 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>

Edit .. My full flask code:

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()
+4
source share
1 answer

You send a message to a function entry(), and your function entry_post()listens for another route; it is registered only for listening /data, and not /:

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

The route /does not accept POST, only are allowed by default GET, HEADand OPTIONS.

Adjust your shape accordingly:

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

Note that Flask does not restart your source unless you enable debugging :

app.run(debug=True)
+3

Source: https://habr.com/ru/post/1543605/


All Articles