简体   繁体   中英

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

./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

# 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

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). To fix this in 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

run

./manage.py collectstatic

you should see your generated 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:

With missing comma, ('js/app/controllers.js') is a string and throws 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',
    },
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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