Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Flask Basics Character Builder Cookies

'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.

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

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