Django pipeline was unable to access the file. access error

I am using Django pipeline to minify and compress assets, but there seems to be an error when I try to run

./manage collectstatic

I am getting 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

      

+3


source to share


2 answers


Delete

STATIC_PATH +

      

both from source_filenames

and fromoutput_filename

I suspect the reason you added that because of ./manage.py collectstatic

not outputting the result in your directory js/app

(which is 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

+3


source


Another reason this can happen is to omit a comma in a tuple source_filenames

with a single filename, making it a line:

With a missing comma, ('js/app/controllers.js')

is a string and throws out 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',
    },
}

      

+1


source







All Articles