【问题标题】:django, compressor and foundation scssdjango,压缩机和基础 scss
【发布时间】:2013-03-11 15:57:45
【问题描述】:

您好,我正在尝试使用 django-compressor 的预编译器将基础 scss 集成到 django 中,项目如下所示:

├── manage.py
├── requirements.txt
├── static
│   ├── config.rb
│   ├── humans.txt
│   ├── index.html
│   ├── javascripts
│   │   ├── foundation
│   │   │   ├── foundation.alerts.js
│   │   │   ├── foundation.clearing.js
│   │   │   ├── foundation.cookie.js
│   │   │   ├── foundation.dropdown.js
│   │   │   ├── foundation.forms.js
│   │   │   ├── foundation.joyride.js
│   │   │   ├── foundation.js
│   │   │   ├── foundation.magellan.js
│   │   │   ├── foundation.orbit.js
│   │   │   ├── foundation.placeholder.js
│   │   │   ├── foundation.reveal.js
│   │   │   ├── foundation.section.js
│   │   │   ├── foundation.tooltips.js
│   │   │   └── foundation.topbar.js
│   │   └── vendor
│   │       ├── custom.modernizr.js
│   │       ├── jquery.js
│   │       └── zepto.js
│   ├── MIT-LICENSE.txt
│   ├── robots.txt
│   ├── sass
│   │   ├── app.scss
│   │   ├── normalize.scss
│   │   └── _settings.scss
│   └── stylesheets
│       ├── app.css
│       └── normalize.css
├── templates
│   ├── 404.html
│   ├── 500.html
│   ├── admin
│   │   └── base_site.html
│   └── base.html
└── weddings
    ├── __init__.py
    ├── __init__.pyc
    ├── local_settings.py
    ├── local_settings.pyc
    ├── settings.py
    ├── settings.pyc
    ├── urls.py
    ├── urls.pyc
    └── wsgi.py

并且预编译器在 settings.py 中看起来像这样

COMPRESS_PRECOMPILERS = (
    ('text/x-scss', 'sass --scss --compass {infile} {outfile}'),
)

当我使用 nginx + uwsgi 运行它时,出现以下错误:

Syntax error: File to import not found or unreadable: foundation/foundation-global.
              Load paths:
                /etc/uwsgi/vassals
                /etc/uwsgi/vassals/sass
                /srv/www/weddings/gems/compass-0.12.2/frameworks/blueprint/stylesheets
                /srv/www/weddings/gems/compass-0.12.2/frameworks/compass/stylesheets
                Compass::SpriteImporter
                /srv/www/weddings/gems/bourbon-3.1.1/app/assets/stylesheets
                /srv/www/weddings/gems/bourbon-3.1.1/app/assets/stylesheets
        on line 2 of /srv/www/weddings/weddings/static/sass/_settings.scss
        from line 2 of /srv/www/weddings/weddings/static/sass/app.scss
  Use --trace for backtrace.

我怀疑它没有读取 config.rb 或者 config.rb 中的设置有误:

http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"

【问题讨论】:

    标签: django sass zurb-foundation


    【解决方案1】:

    我目前的工作是在 ocnfig.rb 所在的文件夹中运行 sass 命令

    COMPRESS_PRECOMPILERS = (
        ('text/x-scss', 'cd /srv/www/project/name/static && sass --scss --compass {infile} {outfile}'),
    )
    

    【讨论】:

      【解决方案2】:

      因为您有一个config.rb 文件,所以您有一个 Compass 项目。

      Compass 项目应该使用compass 命令行工具编译,而不是sass 命令行工具。

      正如您已经发现的那样,编译应该从项目文件夹中启动。但是将路径硬编码到 settings.py 中是个坏主意,因为这会使您的项目不可移植。

      您应该使用os.path.dirname(os.path.realpath(__file__)) 来发现当前脚本的路径,而不是硬编码路径。要更改相对于settings.py 的文件夹,请像这样使用os.path.join()(根据需要调整,可以使用..):

      os.path.join(os.path.dirname(os.path.realpath(__file__)), "static")
      

      另外,您的settings.py 中可能已经有PROJECT_DIR 变量。用它来使这条线更干净。

      【讨论】:

      • 谢谢,关于你对硬编码路径的推荐,我实际上使用的是你推荐的('text/x-scss', 'cd {0}/static && sass --scss --compass --require bourbon.rb {{infile}} {{outfile}}'.format(PROJECT_ROOT)),,我认为在这里显示实际路径会更具可读性。
      【解决方案3】:

      对@James Lin 的一点改进

      COMPRESS_PRECOMPILERS = (
          # ('text/x-scss', 'django_libsass.SassCompiler'),
          # ('text/x-scss', 'sass --scss {infile} {outfile}'),
          ('text/x-scss', 'sass --scss --compass {infile} {outfile}'),
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-07
        • 2017-01-02
        • 2014-12-10
        • 2020-12-12
        • 2014-04-22
        • 1970-01-01
        相关资源
        最近更新 更多