我里面有很多CSS文件SITE_ROOT/sources/css,我想在SITE_ROOT/static/css使用django-pipeline时只压缩一个文件.
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
STATICFILES_DIRS = (
os.path.join(SITE_ROOT, 'sources'),
)
PIPELINE_CSS = {
'responsive': {
'source_filenames': (
'css/smartphones.css',
'css/tablets.css',
),
'output_filename': 'css/responsive.min.css',
}
}
Run Code Online (Sandbox Code Playgroud)
运行后,collectstatic我在static/文件夹中看到了缩小文件(responsive.min.css),但是还有一个位于该sources/文件夹中的所有文件的副本和一个django管理静态文件的副本.如何只获取STATIC_ROOT文件夹中的缩小文件?
您可以创建自己的STATICFILES_STORAGE类,继承自PipelineStorage,它扩展了的行为PipelineMixin。像这样的东西(需要测试):
import shutil
import os.path
from django.conf import settings
from pipeline.storage import PipelineStorage
class PipelineCleanerStorage(PipelineStorage):
def post_process(self, paths, dry_run=False, **options):
# Do the usual stuff (compress and deliver)
res = PipelineStorage.post_process(self, paths, dry_run=False, **options)
# Clean sources files there
shutil.rmtree(os.path.join(settings.BASE_DIR, "static/sources"))
yield res
Run Code Online (Sandbox Code Playgroud)
并在您的中使用它settings.py而不是PipelineStorage.
另一种方法可能是运行自动化任务来在每次收集静态后清理此目录。这将是相同的想法,但在manage命令本身上。
| 归档时间: |
|
| 查看次数: |
220 次 |
| 最近记录: |