【问题标题】:flask_asset seems to not find sass file but directory is okflask_asset 似乎找不到 sass 文件,但目录没问题
【发布时间】:2020-07-26 14:47:06
【问题描述】:

我第一次尝试使用flask_asset。 这是我的 init.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

我的错误在哪里?谢谢

【问题讨论】:

    标签: css flask flask-assets


    【解决方案1】:

    这是由于未正确安装 sass 库。 Pycharm 似乎无法直接添加这个库...

    【讨论】:

      猜你喜欢
      • 2012-06-26
      • 1970-01-01
      • 2013-07-03
      • 1970-01-01
      • 2022-01-14
      • 2011-04-30
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多