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 trialKevin 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
2 Answers
Kenneth Love
Treehouse Guest TeacherAh, 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
Treehouse Guest TeacherUpdated. Everything should be ok now.
Kenneth Love
Treehouse Guest TeacherLike Freddy Heppell said, you have to define the allowed methods in the route.
Kevin Lozandier
Courses Plus Student 53,747 PointsI had POST
defined; I'll see if changing it to lowercase fixes the problem...
Kevin Lozandier
Courses Plus Student 53,747 PointsThe "method is not allowed" error also occurs with the completed version of the project; I forgot to mention that... :/
Freddy Heppell
9,753 PointsFreddy Heppell
9,753 PointsYou have allowed POST right? Like this:
@app.route('/save', methods=['post'])