我第一次尝试使用flask_asset。这是我的初始化.py 代码:
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)
我创建了一个 assets.py 文件:
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'
)
在我的 html 文件中:
{% block css %}
{% assets "public_layout_css" %}
<link rel="stylesheet" href="{{ ASSET_URL }}" />
{% endassets %}
{% endblock %}
当我尝试运行 html 页面时,这是错误:
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError:[Errno 2] 没有这样的文件或目录:'sass':'sass'
但是在我的静态目录中,我有 sass 文件夹,其中包含以下文件:
sass/milligram/milligram.sass
sass/utils.sass
sass/public.sass
我的错误在哪里?谢谢