0PricingLogin
Flask Academy · Lesson

Declare Allowed Methods on a Route

Pass methods to @app.route for GET and POST.

Routes Default to GET

Every Flask route you write so far only answers GET requests. Browsers use GET to fetch pages, so it is the natural default.

The methods Argument

To accept other verbs, pass a methods list to the route decorator. It tells Flask exactly which HTTP verbs the view will handle.

@app.route("/submit", methods=["GET", "POST"])
def submit():
    return "ok"

All lessons in this course

  1. Declare Allowed Methods on a Route
  2. Branch Logic by request.method
  3. Read POST Data from the Body
  4. 405 Method Not Allowed Explained
← Back to Flask Academy