Code Monkey home page Code Monkey logo

Comments (9)

nickjj avatar nickjj commented on May 25, 2024

Hi,

You can have as many blueprints and template directories as you'd like but yeah this extension is only going to look in a single static directory to digest files. Mainly because in most applications you'd output your bundles to 1 specific directory (your static directory) and Flask will serve them from there. How you bundle those files are up to you.

from flask-static-digest.

ericsouza avatar ericsouza commented on May 25, 2024

I was able to compile, but tried different settings to blueprint, some cases the static_url_for method didn't match the filename to the file on the cache_manifest, other cases I just got a 404 loading the asset. I just wonder how I should config my blueprint.

Basically I was not able to set my blueprint this way:

my_blueprint = Blueprint(
    "my_blueprint", 
    __name__, 
    static_folder="/static/my_blueprint",
    static_url_path="/static/my_blueprint", 
    template_folder="../templates/my_blueprint"
    )

and use static_url_for like that:

<link rel="stylesheet" href="{{static_url_for('my_blueprint.static', filename='css/style.css')}}">

the static_url_for does not match filename to cache_manifest and fallback to the file without md5 hash. If I change the above code to this:

<link rel="stylesheet" href="{{static_url_for('static', filename='my_blueprint/css/style.css')}}">

It works just fine. But I don't think its the best options. Do you know if I am doing some mistake?

from flask-static-digest.

nickjj avatar nickjj commented on May 25, 2024

The static_url_for helper directly calls url_for btw. It would be interesting if it behaved differently than url_for. With your first example if you use url_for instead (temporarily of course), do you get the same 404?

from flask-static-digest.

ericsouza avatar ericsouza commented on May 25, 2024

with url_for I get the normal file, without md5 hash. If I understood correctly this extensions uses the filename to make the match with cache_manifest.json and find the md5 version. My cache_manifest.json look like this:

{"my_blueprint/css/style.css": "my_blueprint/css/style-1688c8210b6509d702b1adb96bc4d0f3.css"}

This explains why this work:

<link rel="stylesheet" href="{{static_url_for('static', filename='my_blueprint/css/style.css')}}">

But this doesn't:

<link rel="stylesheet" href="{{static_url_for('my_blueprint.static', filename='css/style.css')}}">

I'm pretty sure that the problem is the way I think static_folder and static_url_for arguments for Blueprint is wrong. So I will just stick without using my_blueprint.static when using static_url_for. Thanks for your time!! :)

from flask-static-digest.

nickjj avatar nickjj commented on May 25, 2024

Yeah this extension will add the md5 hash but I was curious if {{ url_for('my_blueprint.static', filename='css/style.css' )} worked in your case, in the sense that it didn't 404.

Flask's docs mention using my_blueprint.static with url_for will work as long as your Blueprint has a url_prefix set.

from flask-static-digest.

ericsouza avatar ericsouza commented on May 25, 2024

I had no 404 with {{ url_for('my_blueprint.static', filename='css/style.css' )}

Well, thanks for the help, I will close the issue

from flask-static-digest.

nickjj avatar nickjj commented on May 25, 2024

No problem.

Sounds like I should add a FAQ item in the docs on how to reference static files within a Blueprint.

from flask-static-digest.

GhostChasser avatar GhostChasser commented on May 25, 2024

hi there, any updates on this one ? @ericsouza how did you compile files from blueptrints ?

from flask-static-digest.

ericsouza avatar ericsouza commented on May 25, 2024

hi there, any updates on this one ? @ericsouza how did you compile files from blueptrints ?

I endup splitting the frontend from the backend, so my flask application didn't have to deal with static files

from flask-static-digest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.