close

[Solved] Method Not Allowed flask 405

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Method Not Allowed flask 405 in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Method Not Allowed flask 405 Error Occurs?

Today I get the following error Method Not Allowed flask 405 in python.

How To Solve Method Not Allowed flask 405 Error ?

  1. How To Solve Method Not Allowed flask 405 Error ?

    To Solve Method Not Allowed flask 405 Error When you visit /registrazione in your browser, it will do a GET request first. Only once you submit the form your browser will do a POST. So for a self-submitting form like yours, you need

  2. Method Not Allowed flask 405

    To Solve Method Not Allowed flask 405 Error When you visit /registrazione in your browser, it will do a GET request first. Only once you submit the form your browser will do a POST. So for a self-submitting form like yours, you need

Solution 1

This is because you only allow POST requests when defining your route.

When you visit /registrazione in your browser, it will do a GET request first. Only once you submit the form your browser will do a POST. So for a self-submitting form like yours, you need to handle both.

Using

@app.route('/registrazione', methods=['GET', 'POST']) 

should work.

Solution 2

Just for people reading on it now. You have to render the /registrazione first, befor you can access the form data. Just write.

@app.route("/registrazione")
    def render_registrazione() -> "html":
        return render_template("registrazione.html")

before you define def registration(). Sequence is key. You can’t access data before the even are available. This is my understanding of the problem.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read