简体   繁体   English

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

[英]Django-pipeline is not been able to access a file. Access Denied Error

I am using Django-pipeline for asset minification and compression but there seems to be an error when I try to run 我正在使用Django-pipeline进行资产缩小和压缩,但是当我尝试运行时似乎出现了错误

./manage collectstatic

I get the following error.. 我收到以下错误..

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

Here is my settings.py file 这是我的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',
    },
}

Here is my file structure 这是我的文件结构

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

Remove 去掉

STATIC_PATH +

from both source_filenames and output_filename 来自source_filenamesoutput_filename

I suspect the reason you added that was due to ./manage.py collectstatic not producing an output in your js/app directory (thats what caused my confusion). 我怀疑你添加的原因是由于./manage.py collectstaticjs/app目录中没有产生输出(这就是导致我混淆的原因)。 To fix this in settings.py set 要在settings.py设置中修复此问题

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

run

./manage.py collectstatic

you should see your generated output_filename 你应该看到生成的output_filename

Another reason this can happen is if you're missing a comma in the source_filenames tuple with one filename, which makes it a string: 这可能发生的另一个原因是如果你在source_filenames元组中缺少一个带有一个文件名的逗号,这使它成为一个字符串:

With missing comma, ('js/app/controllers.js') is a string and throws SuspiciousFileOperation : 缺少逗号, ('js/app/controllers.js')是一个字符串并抛出SuspiciousFileOperation

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

Fixed: 固定:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM