Django-pipeline无法访问文件。访问被拒绝错误

时间:2014-10-05 20:13:04

标签: django django-staticfiles django-pipeline

我正在使用Django-pipeline进行资产缩小和压缩,但是当我尝试运行时似乎出现了错误

./manage collectstatic

我收到以下错误..

django.core.exceptions.SuspiciousFileOperation: Attempted access to '/home/darwesh/projects/first/api/static/js/app/check.js' denied.

这是我的settings.py文件

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'api/static'),
)

STATIC_ROOT = os.path.join(BASE_DIR, 'api/static_final/')

STATIC_URL = '/static/'

STATIC_PATH = os.path.join(BASE_DIR, 'api/static/')


# pipeline settings 
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_JS = {
    'check': {
        'source_filenames' : (
            STATIC_PATH + 'js/app/controllers.js',
        ),
        'output_filename': STATIC_PATH + 'js/app/check.js',
    },
}

这是我的文件结构

project 
|__api
   |__static
      |__js
         |__app
            |__ controllers.js
            |__ check.js  # expected output file

2 个答案:

答案 0 :(得分:3)

删除

STATIC_PATH +
来自source_filenamesoutput_filename

我怀疑你添加的原因是由于./manage.py collectstatic没有在js/app目录中产生输出(这就是导致我混淆的原因)。要在settings.py set

中解决此问题
PIPELINE_ENABLED = True  # pipeline > 1.3
#PIPELINE = True  # pipeline < 1.3
STATIC_ROOT = os.path.join(BASE_DIR, 'project/static')  # this should also be set

运行

./manage.py collectstatic

您应该会看到生成的output_filename

答案 1 :(得分:1)

这种情况可能发生的另一个原因是,如果你在source_filenames元组中缺少一个带有一个文件名的逗号,这会使它成为一个字符串:

如果缺少逗号,则('js/app/controllers.js')为字符串并抛出SuspiciousFileOperation

PIPELINE_JS = {
    'check': {
        'source_filenames' : (
            'js/app/controllers.js'
        ),
        'output_filename': 'js/app/check.js',
    },
}

修正:

PIPELINE_JS = {
    'check': {
        'source_filenames' : (
            'js/app/controllers.js',
        ),
        'output_filename': 'js/app/check.js',
    },
}