miracle2k / flask-assets

Flask webassets integration.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clashing of subdirectories of 'static' folder and blueprints with same name

panda-byte opened this issue · comments

According to the flask-assets documentation about blueprints, a path prefix is used to denote the use of blueprint-specific static folders when defining bundles. However, this caused issues for my project, because I'm using a single shared {APP_ROOT}/static directory for all blueprints, in which I also have subdirectories; so if there's a subdirectory with the same name as a blueprint, flask-assets would give me an TypeError: The referenced blueprint <flask.blueprints.Blueprint object at ...> has no static folder., because it would look for a blueprint-specific static folder {BLUEPRINT_ROOT}/static. In my case, I had a 'debug' blueprint for testing purposes and a 'debug' subdirectory within my {APP_ROOT}/static.
The doc states

If you are using Flask blueprints, you can refer to a blueprint’s static files via a prefix, in the same way as Flask allows you to reference a blueprint’s templates

but I'm not sure the statement about Flask's way of referencing templates is (still) true; when I reference templates in my project, they're always interpreted as paths beneath the app root template directory or the specific blueprint template directory, so the blueprint name is never part of the template path either way.

The ambiguity of the first part of a bundle source path being interpreted as either a blueprint (but only if a blueprint of that name exists) or a subdirectory seems confusing to me. There might be ways to entirely circumvent that using flask-assets or Flask configurations or even the right parameters for the bundle, but I couldn't find what I was looking for in the docs. I'm sorry if I missed a solution that I could I have gotten by looking into it more carefully.

I'm not sure if there's a better way to do this (maybe a blueprint keyword argument in the Bundle constructor, which would apply to all input and output files though, or some other way to denote the use of blueprints on a file-by-file base), but I just wanted to point out that this can lead to some confusion or potentially to unnecessary limitations on how to name things in the project.

Having had the same issue you described in one of my projects as well, I found this to work: instead of using absolute paths, you have to use relative paths for every folder under /static directory.

So for example if your path is /static/some-folder/file.css, then in your bundle the path would change to become: ./some-folder/file.css.

However I agree with you that this approach is rather illogical and confusing.