【发布时间】:2015-11-05 11:53:42
【问题描述】:
好的。我使用 django-pipeline 快疯了,我离完全不使用它只有一步之遥。
我还没有生产。以下所有内容都在开发 (DEBUG=True) 模式下发生。我的 css 静态文件位于名为“project/static/css”的目录中,我将它们收集在名为“project/static_remote/css”的目录中(在我自己的开发服务器中)。
我设置了以下内容:
import os
from os.path import abspath, dirname, join
# PATH CONFIGURATION
here = lambda *x: join(abspath(dirname(__file__)), *x)
PROJECT_ROOT = here("..", "..")
root = lambda *x: join(abspath(PROJECT_ROOT), *x)
# STATIC FILES CONFIGURATION
STATIC_ROOT = root('static_remote')
STATIC_URL = '/static/'
STATICFILES_DIRS = (root('static'), )
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
# PIPELINE CONFIGURATION
PIPELINE_ENABLED = True
PIPELINE_CSS = {
'master': {
'source_filenames': (
'css/fonts.css',
'css/animate.css',
'css/style.css',
'css/responsive.css',
),
'output_filename': 'css/master.css',
},
}
当我运行collectstatic 时,一切顺利,master 分支中的所有文件(加上压缩的master.css)都成功复制到“project/static_remote/css”中。直到这里万岁!
但是,当我 runserver 时,我的模板中的 {% static 'master' %}(href='/static/css/master.css') 找不到我的压缩文件(显然我有 {% load pipeline %})。如果我运行findstatic 'css/master.css',同样的情况也适用。为什么会这样?
所有其他文件 (fonts.css animate.css etc) 都由 findstatic 找到。
我怀疑这是因为“project/static/css”中没有master.css 的副本。还是因为我有DEBUG = True 而发生这种情况?
如果我手动将“master.css”从“project/static_remote/css”复制到“project/static/css”,那么一切正常,但我不希望这样。请问有什么建议吗?
【问题讨论】: