django,压缩机和基础scss

Jam*_*Lin 3 django sass zurb-foundation

嗨我正在尝试使用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
Run Code Online (Sandbox Code Playgroud)

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

COMPRESS_PRECOMPILERS = (
    ('text/x-scss', 'sass --scss --compass {infile} {outfile}'),
)
Run Code Online (Sandbox Code Playgroud)

当我用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.
Run Code Online (Sandbox Code Playgroud)

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

http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
Run Code Online (Sandbox Code Playgroud)

And*_*aus 5

当你有一个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")
Run Code Online (Sandbox Code Playgroud)

此外,您可能已经拥有PROJECT_DIRvar settings.py.用它来使这条线更清洁.