I m trying for the first time to use flask_asset. this is my init.py code:
from application import assets
def create_app(config_name):
app = Flask(__name__, instance_relative_config=True)
# security
app.config['SECRET_KEY'] = SECRET_KEY
# trace db modifications
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Ensure responses aren't cached
@app.after_request
def after_request(response):
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Expires"] = 0
response.headers["Pragma"] = "no-cache"
return response
# Ensure templates are auto-reloaded
app.config["TEMPLATES_AUTO_RELOAD"] = True
# define where is database
app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
db.init_app(app)
Bootstrap(app)
# Assets for CSS and JS
assets_env = Environment(app)
assets_loader = PythonAssetsLoader(assets)
for name, bundle in assets_loader.load_bundles().items():
assets_env.register(name, bundle)
I create an assets.py file:
from flask_assets import Bundle
public_layout_css = Bundle(
'sass/milligram/milligram.sass',
'sass/utils.sass',
'sass/public.sass',
filters=['sass', 'cssmin'],
output='public/public.min.css'
)
And in my html file :
{% block css %}
{% assets "public_layout_css" %}
<link rel="stylesheet" href="{{ ASSET_URL }}" />
{% endassets %}
{% endblock %}
When I try to run html page this is the error:
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'sass': 'sass'
But in my static directory I have sass folder with these files in:
sass/milligram/milligram.sass
sass/utils.sass
sass/public.sass
Where is my mistake ? Thanks
this was due to sass library not properly installed. Pycharm seems having issue to add this library directly...