Skip to content

Nested blueprints are not respected when mounted on subdomains #4834

@yeraydiazdiaz

Description

@yeraydiazdiaz

Hello, and thanks for all your work 🙏🏻

Nested blueprints as described in the docs work perfectly fine when using url_prefix. However, when mounting the parent blueprint using a subdomain, the child routes are not accessible.

from flask import Flask
from flask import Blueprint

app = Flask(__name__)
app.config["SERVER_NAME"] = "localhost:5000"
parent = Blueprint("parent", __name__)
child = Blueprint("child", __name__)

@app.route('/')
def index():
    return "index"

@parent.route('/')
def parent_index():
    return "parent"

@child.route('/child/')
def child_index():
    return "child"

parent.register_blueprint(child)
app.register_blueprint(parent, subdomain="api")


if __name__ == '__main__':
    app.run(debug=True)

The index route works as expected:

❯ http http://localhost:5000/
HTTP/1.1 200 OK
Connection: close
Content-Length: 5
Content-Type: text/html; charset=utf-8
Date: Tue, 04 Oct 2022 10:44:10 GMT
Server: Werkzeug/2.2.2 Python/3.10.4

index

So does the parent route in the subdomain:

❯ http http://api.localhost:5000/
HTTP/1.1 200 OK
Connection: close
Content-Length: 6
Content-Type: text/html; charset=utf-8
Date: Tue, 04 Oct 2022 10:44:06 GMT
Server: Werkzeug/2.2.2 Python/3.10.4

parent

But the child responds with a 404:

❯ http http://api.localhost:5000/child/
HTTP/1.1 404 NOT FOUND
Connection: close
Content-Length: 207
Content-Type: text/html; charset=utf-8
Date: Tue, 04 Oct 2022 10:45:42 GMT
Server: Werkzeug/2.2.2 Python/3.10.4

<!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>

If we change the subdomain="api" for url_prefix="/api" when registering the blueprint however everything works as expected:

❯ http http://localhost:5000/api/
HTTP/1.1 200 OK
Connection: close
Content-Length: 6
Content-Type: text/html; charset=utf-8
Date: Tue, 04 Oct 2022 10:46:53 GMT
Server: Werkzeug/2.2.2 Python/3.10.4

parent

❯ http http://localhost:5000/api/child/
HTTP/1.1 200 OK
Connection: close
Content-Length: 5
Content-Type: text/html; charset=utf-8
Date: Tue, 04 Oct 2022 10:46:59 GMT
Server: Werkzeug/2.2.2 Python/3.10.4

child

This was surprising to me as I expected the same nesting to apply regardless of whether the parent is mounted using a subdomain or a URL prefix. Am I missing something?

Environment:

  • Python version: 3.10
  • Flask version: 2.2.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions