python - Django Pipeline 生成空文件

标签 python django assets django-pipeline

我有一个新的 Django 项目,一切似乎都工作正常。我正在使用 Django 管道,但是当我运行“collectstatic”命令时,它会生成所有文件,但我的主 css 和 js 文件是空白的,js 文件包含...

(function(){}).call(this);

但我的代码都没有。这是我的设置:

PIPELINE_YUGLIFY_BINARY = os.path.join(BASE_DIR, 'node_modules/yuglify/bin/yuglify')
(to get above line working, I ran 'ln -s /usr/bin/nodejs /usr/bin/node')

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',
)

PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'

PIPELINE_CSS = {
    'stylesheets': {
        'source_filenames': (
        'css/base.css',
    ),
        'output_filename': 'css/base.css',
        'extra_context': {
            'media': 'screen,projection',
        },
    },
}

PIPELINE_JS = {
    'scripts': {
        'source_filenames': (
            'js/vendor/jquery.js',
            'js/base.js',
        ),
        'output_filename': 'javascripts/base.js',
    }
}

最佳答案

所有内容都在本地工作,但是当我在生产中尝试“colectstatic”命令时,它只生成了空白文件。现在可以正常工作了,我没有在生产文件设置中指定“STATICFILES_DIRS”。

STATIC_URL = '/static/'

STATIC_ROOT = '/var/location/to/your/static/files'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

关于python - Django Pipeline 生成空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33289688/

相关文章:

python - 我可以使用 `numpy.bincount` 并行化 `xarray.apply_ufunc` 吗?

python - 错误 : "You are trying to add a non-nullable field"

ios - xcode 9.2 pdf 矢量图像在 iOS 8.2 及更低版本下损坏

ios - 需要将 .MP4 文件从文档文件夹保存到照片库,但 Assets url 返回 nil

python - 如何从python中的N个不同正态分布中采样M次?在处理时间方面有没有 "faster"方式?

python - 相位相关

linux - 通过 Django 运行有限数量的进程

python - docker crontab : not found

ios - 在 xcode 上管理视觉 Assets (引用、复制或两者)?

python - Google App Engine (Python) 中的简单 Facebook 连接