Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Flask Basics Character Builder Cookies

Kevin Lozandier
PLUS
Kevin Lozandier
Courses Plus Student 53,747 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
Courses Plus Student 53,747 Points

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

Kevin Lozandier
Kevin Lozandier
Courses Plus Student 53,747 Points

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