-
-
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
blueprint 404 error handler not honored with url_prefix #1498
Comments
I've stumbled upon this problem as well and it made me scratch my head for hours. Until I found this solution by @svieira. So the solution for your problems would be to do something like this: @blueprint.route("/<path:invalid_path>")
def handle_unmatchable(*args, **kwargs):
raise NotFound() It kind of makes sense that it doesn't match your Blueprint when the path it's looking for doesnt exist in the URL mapping. Having said that I see no reason why not to allow the Blueprint to catch the 404 when it's a sub-path of its own |
Besides the workaround with the wildcard-ish rule I don't think there's any easy way to have blueprint-local 404 handlers. All Flask should probably show a warning when registering 404/405 handlers for a blueprint though. |
On 06/14/2015 10:40 AM, Adrian wrote:
If you use that workaround you're actually telling to flask that will be Using this solution breaks many things, for example:
I think that a solution could be found. |
But there might not always be a dedicated path/prefix for a blueprint.... |
On 06/14/2015 12:15 PM, Adrian wrote:
The prefix do not necessary needs. When you register routes you know for |
Yes, when registering routes. But how do you know it for a 404 candidate? It does not match anything within a Blueprint. You might very well have to blueprints with the same url prefix. |
If does not match anything and you don't have a prefix you will use the top level handler for 404. Two blueprints with the same url_prefix it is a very insane configuration. In this case you can:
|
@ael-code - using two blueprints with the same URL-prefix can have a sane rational. For example, switching over to a different Flask-Rest* extension and for an API - new endpoints use the new extension and old endpoints get migrated over one at a time - but they are all under the same The wildcard Here are a couple of solutions that come to mind:
|
@ael-code What do you mean it breaks 405 response generation? |
Reproduce the bug:
url_prefix="/blue"
Now, if you visit some not existent page under blueprint url prefix, like
/blue/notExist
you will recive response from the main app 404 error handler.The only way to trigger the blueprint 404 error handler is by calling
abort(404)
from within the blueprint.The correct behaviour would be to choose which error handler to activate also on the basis of the
url_prefix
parameter.Response:
The text was updated successfully, but these errors were encountered: