kfk
kfk

Reputation: 841

Static folder with blueprints in flask

I have a static file (SF), I try to reach it as per the documentation. So, having a blueprint registered with the name "application", I would expect to find the static file in:

/application/static/SF

However, this does not work. But if I create the blueprint with an url_prefix condition:

application = Blueprint('application',__name__,template_folder='templates',
                        url_prefix='/test',static_folder='static)

I am indeed able to find the static file now in:

/test/static/SF

Is there any particular reason of this strange behavior? Am I misinterpreting the flask docs?

Upvotes: 2

Views: 1988

Answers (1)

Sean Vieira
Sean Vieira

Reputation: 159865

While blueprints are often used to enable splitting an application up into distinct sub-applications that is not their only use - they can also be used to attach functionality to the application that is not related to new URL routes (filters, for example).

Because they can be used for more than just routes it looks like the decision was made to not auto-mount them. Because the blueprint may be used as a mix-in, it looks like the decision was made to not auto-mount them under a particular sub-url.

Upvotes: 4

Related Questions