Skip to content

url_for() is broken with multiple same blueprint #4376

@sergiokessler

Description

@sergiokessler

my situation is something like this:

api.py

def blueprint_maker(bpname, db_session):

    api = Blueprint(bpname, __name__)
    [...]
    @api.route('/ping', methods=['GET'])
    def ping():
        response = {
            'data': [{
                'echo': 'echo!',
                'source': url_for('api.ping')
            }]
        }
        return jsonify(response)

    return api

and then:

main.py

[snip]
ar = blueprint_maker('ar', SessionLocal_ar)
uy = blueprint_maker('uy', SessionLocal_uy)
br = blueprint_maker('uy', SessionLocal_br)
pt = blueprint_maker('uy', SessionLocal_pt)
[...]


app.register_blueprint(ar, url_prefix='/ar')
app.register_blueprint(uy, url_prefix='/uy')
app.register_blueprint(ar, url_prefix='/br')
app.register_blueprint(uy, url_prefix='/pt')
[...]

I expected url_for() to just work in this scenario, but instead, it gives me:

Could not build url for endpoint 'api.ping'. Did you mean 'ar.ping' instead?

isn't this supposed to work?

Environment:

  • Python version: 3.9
  • Flask version: 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions