【问题标题】:Why django-pipeline does not collect static?为什么 django-pipeline 不收集静态?
【发布时间】:2017-08-03 15:45:07
【问题描述】:

我已关注 django-pipeline 文档,但在收集静态时遇到问题,控制台显示未找到指定文件。

collectstatic 没有 djanog-pipeline 的作品。我还尝试添加与manage.py 相同级别的静态文件,但没有任何区别...

这是我的应用树的配置方式:

Globalapp : (root folder)
    - src (the base that contains all my django files)
        -- staticfiles (folder here after collectstatic)

        -- manage.py (file)

        -- app (folder, where settings.py is)
           ...
        -- pages (folder, where static files are)
           --- static
               - css
                 -- main.css
...

以下是我配置 settings.py 的方式:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

INSTALLED_APPS = [
    ...
    'pipeline',
]

...

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
#tried : STATIC_ROOT = os.path.join(BASE_DIR, 'pages')

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',
)

PIPELINE = {
    'COMPILERS': (
        'pipeline.compilers.stylus.StylusCompiler',
    ),
    'STYLESHEETS': {
        'pages': {
            'source_filenames': (
              'css/main.css',
            ),
            'output_filename': 'designer.css',
        },
    },
}

我现在在本地工作,当我运行python manage.py collectstatic时出现错误,我做错了什么吗?


这是回溯:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 199, in handle
    collected = self.collect()
  File "C:\Python34\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 139, in collect
    for original_path, processed_path, processed in processor:
  File "C:\Python34\lib\site-packages\pipeline\storage.py", line 26, in post_process
    packager.pack_stylesheets(package)
  File "C:\Python34\lib\site-packages\pipeline\packager.py", line 100, in pack_stylesheets
    variant=package.variant, **kwargs)
  File "C:\Python34\lib\site-packages\pipeline\packager.py", line 118, in pack
    content = compress(paths, **kwargs)
  File "C:\Python34\lib\site-packages\pipeline\compressors\__init__.py", line 78, in compress_css
    css = getattr(compressor(verbose=self.verbose), 'compress_css')(css)
  File "C:\Python34\lib\site-packages\pipeline\compressors\yuglify.py", line 20, in compress_css
    return self.compress_common(css, 'css', settings.YUGLIFY_CSS_ARGUMENTS)
  File "C:\Python34\lib\site-packages\pipeline\compressors\yuglify.py", line 14, in compress_common
    return self.execute_command(command, content)
  File "C:\Python34\lib\site-packages\pipeline\compressors\__init__.py", line 247, in execute_command
    stdin=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\Python34\lib\subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "C:\Python34\lib\subprocess.py", line 1114, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The specified path to the file was not found.

【问题讨论】:

  • 你的 manage.py 在哪里? (src 还是 Globalapp?)
  • 你的 BASE_DIR 指向哪里?
  • 你能确认你的 BASE_DIR 指向任何文件夹吗?
  • @zypro 用 base_dir 更新了我的答案
  • 那么您的文件夹“staticfiles”在哪里?也许你应该尝试使用STATIC_ROOT = os.path.join(BASE_DIR, 'pages')。或者而不是页面文件夹静态里面。不确定你的结构......

标签: python django django-pipeline


【解决方案1】:

我最终使用了django-compressordjango-sass-processor。哪个像 django-pipeline 一样工作,我找不到这个特定问题的原因,但是一切都解决了这些其他包,它们在组合时与管道几乎相同。

如果您在使用 pip 安装 django-compressor 时遇到问题,请尝试使用以下命令:

pip install rcssmin --install-option="--without-c-extensions"
pip install rjsmin --install-option="--without-c-extensions"
pip install django-compressor --upgrade

【讨论】:

    猜你喜欢
    • 2014-02-27
    • 2014-01-25
    • 1970-01-01
    • 2015-08-12
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 2019-05-10
    • 2019-09-21
    相关资源
    最近更新 更多