1

一旦我在我的PIPELINE中定义了“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_DIRSSTATIC_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'
            # }
        },
    }
}
4

0 回答 0