35
If you check the rules registered on the application, you will find these:
[<Rule /static/<filename> (HEAD, OPTIONS, GET) -> static>,
<Rule /<page> (HEAD, OPTIONS, GET) -> simple_page.show>,
<Rule / (HEAD, OPTIONS, GET) -> simple_page.show>]
The first one is obviously from the application ifself for the static files. The other two
are for the show function of the simple_page blueprint. As you can see, they are also
prefixed with the name of the blueprint and separated by a dot (.).
Blueprints however can also be mounted at different locations:
app.register_blueprint(simple_page, url_prefix=/pages)
And sure enough, these are the generated rules:
[<Rule /static/<filename> (HEAD, OPTIONS, GET) -> static>,
<Rule /pages/<page> (HEAD, OPTIONS, GET) -> simple_page.show>,
<Rule /pages/ (HEAD, OPTIONS, GET) -> simple_page.show>]
On top of that you can register blueprints multiple times though not every blueprint
might respond properly to that. In fact it depends on how the blueprint is imple-
mented if it can be mounted more than once.
15.5 Blueprint Resources
Blueprints can provide resources as well. Sometimes you might want to introduce a
blueprint only for the resources it provides.
15.5.1 Blueprint Resource Folder
Like for regular applications, blueprints are considered to be contained in a folder.
While multiple blueprints can originate from the same folder, it does not have to be
the case and it’s usually not recommended.
The folder is inferred from the second argument to Blueprint which is usually
__name__. This argument specifies what logical Python module or package corre-
sponds to the blueprint. Ifit points to an actual Pythonpackage that package (whichis
afolderon the filesystem) is the resource folder. If it’s a module, the package the mod-
ule is contained inwill be the resource folder. You can access the Blueprint.root_path
property to see what the resource folder is:
>>> simple_page.root_path
/Users/username/TestProject/yourapplication
To quickly open sources from this folder you can use the open_resource() function:
with simple_page.open_resource(static/style.css) as f:
code = f.read()
93