django-compressor在STATIC_ROOT/app而不是app/static中编译SCSS文件

mst*_*ger 5 python django django-compressor

我们正在使用django-compressordjango.contrib.staticfiles应用程序,我们在运行django开发服务器和处理我们的SCSS时遇到问题:错误的SCSS文件被编译.这是该版本STATIC_ROOT/app也越来越发现,而不是版本的应用程序/静态的.这使得对SCSS的编辑app/static不会反映在编译的CSS中.

删除所有内容可以STATIC_ROOT/app解决问题,但如果collectstatic由于某种原因执行会导致很多混乱.

有没有办法确保编译app/static文件而不是任何现有的STATIC_ROOT/app文件?

我们在django 1.6中使用django-compressor 1.4,并在django设置文件中使用以下设置:

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    'compressor.finders.CompressorFinder',
)
COMPRESS_PRECOMPILERS = (
    ("text/x-scss", 'sass --scss'),
)
STATICFILES_DIRS = [] #default
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
Run Code Online (Sandbox Code Playgroud)

tut*_*uju 1

您的sass --scss命令COMPRESS_PRECOMPILERS未明确指定目标目录。因此使用默认值,这似乎是stdinstdout

现在,压缩机文档不太清楚 using 的stdout含义;但是,从示例来看,文件似乎最终会出现在COMPRESS_ROOT中(STATIC_ROOT/CACHE在您的情况下默认为root/base/static/CACHE/

我个人喜欢的是明确声明输入/输出目录(以在不同环境中保持不变)。这是一个示例(使用pyScss编译器,但想法是相同的):

scss_cmd = '{python} -mscss -A "{image_output_path}" -a "{static_url}" ' \
    '-S "{static_root}" -o "{{outfile}}" "{{infile}}"'.format(
        python=sys.executable,
        image_output_path=COMPRESS_ROOT,
        static_url=STATIC_URL,
        static_root=os.path.join(PROJECT_ROOT),
    )

COMPRESS_PRECOMPILERS = (
    ('text/x-scss', scss_cmd),
)
Run Code Online (Sandbox Code Playgroud)

(抱歉,如果挖掘出长期被遗忘的问题)