-
-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
url_for can't distinguish a blueprint mounted two times #1091
Comments
@iurisilvio this is expected behaviour. It won't work with absolute name (i.e. |
@jackunion it was just an example. I want to mount the same blueprint with different prefixes and I expect my relative I fixed my problem with multiple blueprints (with the same routes), but I expected Flask store the blueprint in a dict like |
@iurisilvio actually, |
I am really curious what you're trying to do with registering the same blueprint multiple times. The restriction might seem arbitrary, but i can imagine it is in place to avoid gross misuse of Flask's blueprints. |
|
That is not true. This is not expected behaviour, this is a supported use case. |
@danielchatfield have you read the question? |
Yes. The docs give registering a single blueprint multiple times on the same app as an "intended use case". The utility of that is somewhat questionable if |
@untitaker I have a blueprint mounted in In most cases, I'd prefer I just created a blueprint factory to fix this issue for me, using different names. It works fine and is not a huge problem for me. But I consider it a bug, because it is an intended use case (@danielchatfield already quoted it). I never expected a relative |
First, i have to admit that it indeed seems to be an intended usecase. @iurisilvio It basically seems like you're mixing code and data there. Adding a rule |
Yes, I agree. This structure is weird, but it is really the right choice for my app. As I said, it was easy to workaround this issue, but if I rather mount the same blueprint in different paths. Blueprints are perfect to my use case, based on blueprint definition. Unfortunately, |
@danielchatfield this question is about |
@jackunion this issue is about the Two statements from blueprints docs:
|
@iurisilvio and again: |
@jackunion the point of this issue is that it is a bug. |
@jackunion we know it doesn't work, but as per the docs it should work! |
Hmm, this is definitely unexpected behavior, but I'm not sure what we can do about it. The problem is that the endpoint becomes There's no information about which path to prefer. We'd need to send the url prefix to There's also no way to know what other prefixes a blueprint was registered under, so we can't know a prefix to strip and replace with the current blueprint. |
This is really confusing. The same My solution was to just nest my blueprint creation and route definition inside a |
#4074 makes it possible to pass a different A warning is shown when the same blueprint is registered with the same name, it will be an error in Flask 2.1. |
Based on blueprint concept, I expected it to handle relative
url_for
nicely:Both prints write the URL to the first blueprint registered (
/foo/
). Is it possible to mount two times the same blueprint and make relativeurl_for
work? Is this behaviour expected?The text was updated successfully, but these errors were encountered: