Python Flask Basics Character Builder Cookies

Kevin Lozandier
PRO
Kevin Lozandier
Pro Student 53,746 Points

'Method not allowed' error on Workspace and Localhost when attempting to do a POST request within Flask file.

For some reason, I get a 'method not allowed error' when attempting to do any POST requests for routes defined within app.py.

Having no problems doing similar requests within Node.js, Ruby on Rails, and Golang apps, I'm confused on how to resolve this problem.

I thought at first I had to tweak my Apache or Nginx config files on my localhost, but it also occurs in Workspace as well.

Is this a common gotcha associated with Flask, Kenneth Love?

The closest things I found on StackOverflow was the following which seems to be irrelevant: http://stackoverflow.com/questions/12179593/flask-post-error-405-method-not-allowed

Freddy Heppell
Freddy Heppell
9,753 Points

You have allowed POST right? Like this:

@app.route('/save', methods=['post'])

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Ah, the index.html form doesn't have {{ url_for('save') }} in its action attribute. I'll see if I can get the Workspaces and project files updated.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Updated. Everything should be ok now.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Like Freddy Heppell said, you have to define the allowed methods in the route.

Kevin Lozandier
Kevin Lozandier
Pro Student 53,746 Points

I had POST defined; I'll see if changing it to lowercase fixes the problem...

Kevin Lozandier
Kevin Lozandier
Pro Student 53,746 Points

The "method is not allowed" error also occurs with the completed version of the project; I forgot to mention that... :/