-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling HTTP 405 on the blueprint level #1494
Comments
It certainly seems like a rough edge, similar to #1498 |
Kind of, but at least there we know of a workaround. |
@jmagnusson - the way to work around this (just like in #1498) is to compose distinct Flask applications, rather than trying to make a blueprint handle 405s. @untitaker - I think one way to help people for whom this is an issue (for 1.x or 1.0 if that ship hasn't sailed yet) would be to add a new registration method to |
@svieira Interesting idea about using app composition. However, don't we miss out on features like linking between them with |
You would need to add to the set of |
Sounds somewhat messy. I kind of like the simplicity we have today where we just add Blueprints to our app to add more HTTP endpoints. Couldn't there be some other way to make 405 catchable? An idea I have is that we make Flask create "fake routes" for each method in the url_map. This would make it work a bit like your workaround for 404s not being catched by the blueprints. |
You're absolutely right, you could iterate over all the defined routes in a blueprint and add a route handler for the So you are left with either:
|
I really like being able to override the error templates for each blueprint using their errorhandler methods. All error codes work great for me. Except one. 405's are AFAIK not catchable by the blueprint. This is a bit unfortunate when you have a JSON REST API where you want your consumers to be able to parse the data that they get back.
This line in
werkzeug.routing
is where the exception is raised. I feel a bit lost about the whole flow of a request in werkzeug/flask and don't really have any idea what I could do to be able to catch it in the Blueprint. Is this a bug? A known "feature"? Or am I doing something wrong?Here's a test case which shows this behavior:
Running this gives:
A version which tests more error codes can be found in this gist.
The text was updated successfully, but these errors were encountered: