close

[Solved] Flask Error: “Method Not Allowed The method is not allowed for the requested URL”

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Flask Error: “Method Not Allowed The method is not allowed for the requested URL” 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 Flask Error: “Method Not Allowed The method is not allowed for the requested URL” Error Occurs?

Today I get the following error Flask Error: “Method Not Allowed The method is not allowed for the requested URL” in python.

How To Solve Flask Error: “Method Not Allowed The method is not allowed for the requested URL” Error ?

  1. How To Solve Flask Error: “Method Not Allowed The method is not allowed for the requested URL” Error ?

    To Solve Flask Error: “Method Not Allowed The method is not allowed for the requested URL” Error I would try putting the url methods in the app route just like you have in the entry_page function:

  2. Flask Error: “Method Not Allowed The method is not allowed for the requested URL”

    To Solve Flask Error: “Method Not Allowed The method is not allowed for the requested URL” Error I would try putting the url methods in the app route just like you have in the entry_page function:

Solution 1

What is happening here is that database route does not accept any url methods.

I would try putting the url methods in the app route just like you have in the entry_page function:

@app.route('/entry', methods=['GET', 'POST'])
def entry_page():
    if request.method == 'POST':
        date = request.form['date']
        title = request.form['blog_title']
        post = request.form['blog_main']
        post_entry = models.BlogPost(date = date, title = title, post = post)
        db.session.add(post_entry)
        db.session.commit()
        return redirect(url_for('database'))
    else:
        return render_template('entry.html')

@app.route('/database', methods=['GET', 'POST'])        
def database():
    query = []
    for i in session.query(models.BlogPost):
        query.append((i.title, i.post, i.date))
    return render_template('database.html', query = query)

Solution 2

I had a similar problem when I deployed my Flask app in the IIS. Apparently, IIS does not accept route that include an underline (“_”). When I removed the underline, problem was resolved.

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