2013-03-21 117 views
3

你好我想基础SCSS集成到使用Django压缩机的预编译的Django,该项目是这样的:Django的,压缩机和基础SCSS

├── 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" 

回答

5

当你有一个config.rb文件,你有一个指南针项目。

指南针项目应该与compass命令行工具编译,而不是sass命令行工具。

正如你已经发现,编译应该从insie项目文件夹启动。但它是一个糟糕的主意,因为它使你的项目不可移植的硬编码路径到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") 

而且,你可能已经PROJECT_DIR变种在settings.py。使用它来使这条线更清洁。

+1

谢谢,茅塞顿开了一下,关于你推荐的硬编码路径其实我使用你推荐什么'(“文本/ X-SCSS”,“CD {0}/static && sass --scss --compass --require bourbon.rb {{infile}} {{outfile}}'.format(PROJECT_ROOT)),'我认为显示实际路径在这里更具可读性。 – 2013-03-24 22:03:38

+1

伟大的工作!不要忘记upvote。 ;) – 2013-03-25 13:50:11

0

我目前的解决办法是到ocnfig.rb所在的文件夹中运行命令SASS

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

稍加改进,以@詹姆斯林

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