Method not allowed 405 Error in Flask resolved
Your routes are correct? Your methods are correct?
None of the stackoverflow solutions work? You still get the Method not allowed 405 Error?
This is the solution!
I was struggling posting a simple form, I had a route that inserted it into the mongo database and then a return redirect to move the user along.
Everything was correct, I had specified methods=['POST], used the correct route and url_for in the template.. but when I posted and got redirected I still got the error "The method is not allowed for the requested URL"
I was searching for a solution for days, but none of the suggestions applied in my case. Everything was correct with the code.
Solution:
Remove the virtual environment and reinstall the dependencies!
For example on a Linux system:
Delete your current virtual environment (assuming the folder is called "env"):
rm -rf env
Create a new environment:
python3 -m venv env
Source the new environment:
source env/bin/activate
Install your dependencies again:
pip install flask
That's it!
Or you can try to just re-install flask in your original environment:
pip uninstall flask
pip install flask
Let me know if this simpler step works, and we can recommend that instead.