我正在使用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
答案 0 :(得分:3)
删除
STATIC_PATH +
来自source_filenames
和output_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',
},
}