Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
panda-byte opened this issue May 28, 2021 · 1 comment

Comments

@panda-byte
Copy link

panda-byte commented May 28, 2021

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.

@born2discover
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants