好的。我使用 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
master.css
我怀疑这是因为“project/static/css”内部没有副本。还是因为我有这种情况DEBUG = True
?
如果我手动将“master.css”从“project/static_remote/css”复制到“project/static/css”,那么一切正常,但我不希望这样。请问有什么建议吗?