У Django есть исключение, в то время как "collectstatic" django.core.exceptions.SuspiciousFileOperation после добавления STYLESHEETS в ТРУБОПРОВОДЕ - PullRequest
1 голос
/ 29 октября 2019

Как только я определил 'STYLESHEET' в моем ТРУБОПРОВОДЕ и запустил python3 manage.py collectstatic, я получил

django.core.exceptions.SuspiciousFileOperation: The joined path (/) is located outside of the base path component (/opt/luciapp/apps/web/lapp-web-site/src/apps/main/frontend/static)

Я уверен, что этоничего общего с моим STATICFILES_DIRS или STATIC_ROOT

Я посредник в Django Dev и, конечно, новичок во фронтэнде, Пожалуйста, помогите мнес этим.

Я приложил фрагменты журнала ошибок, а также фрагмент настроек

(website) ➜  src git:(clean_for_production) ✗ python3 manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings:

    /opt/luciapp/apps/web/lapp-web-site/public

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
    collected = self.collect()
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 128, in collect
    for original_path, processed_path, processed in processor:
  File "/usr/local/lib/python3.7/site-packages/pipeline/storage.py", line 26, in post_process
    packager.pack_stylesheets(package)
  File "/usr/local/lib/python3.7/site-packages/pipeline/packager.py", line 100, in pack_stylesheets
    variant=package.variant, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pipeline/packager.py", line 114, in pack
    package.paths,
  File "/usr/local/lib/python3.7/site-packages/pipeline/packager.py", line 34, in paths
    return [path for path in self.sources
  File "/usr/local/lib/python3.7/site-packages/pipeline/packager.py", line 27, in sources
    if path not in paths and find(path):
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/finders.py", line 263, in find
    result = finder.find(path, all=all)
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/finders.py", line 98, in find
    matched_path = self.find_location(root, path, prefix)
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/finders.py", line 115, in find_location
    path = safe_join(root, path)
  File "/usr/local/lib/python3.7/site-packages/django/utils/_os.py", line 49, in safe_join
    'component ({})'.format(final_path, base_path))
django.core.exceptions.SuspiciousFileOperation: The joined path (/) is located outside of the base path component (/opt/luciapp/apps/web/lapp-web-site/src/apps/main/frontend/static)

** Вот фрагмент коданастройки: **


# Static
STATIC_ROOT = os.path.join(PROJECT_DIR, 'public')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'apps', 'main', 'frontend', 'static'),
) 

# Pipeline Stack
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',
)

# Django-Pipeline
PIPELINE = {
    'PIPELINE_ENABLED': True,  # TODO: not settings.DEBUG
    'DISABLE_WRAPPER': True,
    'CSS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
    'JS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
    'STYLESHEETS': {
        'vendor': {
            'source_filenames': (
                'vendor/fontawesome/css/all.css'
            ),
            'output_filename': 'assets/css/vendor.min.css',
            'extra_context': {
                'media': 'all'
            }
        }
    },
    'JAVASCRIPT': {
        'vendor': {
            'source_filenames': (
                'vendor/theme/js/core/jquery.min.js',
                'vendor/theme/js/core/popper.min.js',
                'vendor/theme/js/core/bootstrap-material-design.min.js',
            ),
            'output_filename': 'assets/js/vendor.min.js',
            'extra_context': {
                'defer': 'defer'
            }
        },
        'common': {
            'source_filenames': (
                'assets/js/common.js',
            ),
            'output_filename': 'assets/js/common.min.js',
            'extra_context': {
                'defer': 'defer'
            }
        },
        'index': {
            'source_filenames': (
                'assets/js/index.js',
            ),
            'output_filename': 'assets/js/index.min.js',
            # 'extra_context': {
            #     'defer': 'defer'
            # }
        },
    }
}

Версии:

Python==3.7.4
jinja2==2.10.3                  # Jinja Templating
django-pipeline==1.6.14         # Django Pipeline for CSS, HTML
django-htmlmin==0.11.0          # Django HTML Minifier

Спасибо, еще раз!

РЕДАКТИРОВАТЬ 2: проблема была решена в соответствии с новой декларацией ТРУБОПРОВОДА. Я пропустил запятую PIPELINE.STYLESHEETS.vendor.source_filenames

# Django-Pipeline
PIPELINE = {
    'PIPELINE_ENABLED': True,  # TODO: not settings.DEBUG
    'DISABLE_WRAPPER': True,
    'CSS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
    'JS_COMPRESSOR': 'pipeline.compressors.yuglify.YuglifyCompressor',
    'STYLESHEETS': {
        'vendor': {
            'source_filenames': (
                'vendor/fontawesome/css/all.css',
            ),
            'output_filename': 'assets/css/vendor.min.css',
            'extra_context': {
                'media': 'all'
            }
        }
    },
    'JAVASCRIPT': {
        'vendor': {
            'source_filenames': (
                'vendor/theme/js/core/jquery.min.js',
                'vendor/theme/js/core/popper.min.js',
                'vendor/theme/js/core/bootstrap-material-design.min.js',
            ),
            'output_filename': 'assets/js/vendor.min.js',
            'extra_context': {
                'defer': 'defer'
            }
        },
        'common': {
            'source_filenames': (
                'assets/js/common.js',
            ),
            'output_filename': 'assets/js/common.min.js',
            'extra_context': {
                'defer': 'defer'
            }
        },
        'index': {
            'source_filenames': (
                'assets/js/index.js',
            ),
            'output_filename': 'assets/js/index.min.js',
            # 'extra_context': {
            #     'defer': 'defer'
            # }
        },
    }
}
...