【问题标题】:upgrade django-pipeline to 1.2.7 but can't find static files将 django-pipeline 升级到 1.2.7 但找不到静态文件
【发布时间】:2012-05-25 16:32:11
【问题描述】:

我曾经使用 django-pipeline 1.2.6,它在查找静态文件时从来没有遇到过问题。升级后,它现在无法找到静态文件的位置。不知道出了什么问题,但我可能只是遗漏了一些东西。

我收到此错误:

ValueError: The file 'stylesheets/application.css.sass' could not be found with <pipeline.storage.PipelineFinderStorage object at 0x106e8b290>.

我正在使用 django 1.4。这是我的设置:

path = lambda *a: os.path.join(ROOT_PATH, *a)
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = path('assets/')
STATIC_URL = 'assets/'
STATICFILES_DIRS = ()
STATICFILES_FINDERS = (
  'django.contrib.staticfiles.finders.FileSystemFinder',
  'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
INSTALLED_APPS = (
  # ...
  'django.contrib.staticfiles',
  'pipeline',
  'app',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_COMPILERS = (
  'pipeline.compilers.sass.SASSCompiler',
  'pipeline.compilers.coffee.CoffeeScriptCompiler',
)
PIPELINE_CSS = {
    'application': {
        'source_filenames': (
          'stylesheets/application.css.sass',
        ),
        'output_filename': 'stylesheets/application.css',
    },
}

PIPELINE_JS = {
  'application': {
    'source_filenames': (
      'javascripts/application.js.coffee',
    ),
    'output_filename': 'javascripts/application.js',
  }
}

请帮忙。

有趣的花絮:如果我完全删除 PIPELINE_CSS,它也找不到 javascripts/application.js.coffee。

另外一件有趣的事情,无论我使用哪个版本的 django-pipeline,我都会得到以下信息:

$ python manage.py findstatic stylesheets/application.css.sass
No matching file found for 'stylesheets/application.css.sass'.

我做错了什么?

【问题讨论】:

    标签: django sass django-staticfiles


    【解决方案1】:

    如果你有这个,无论你使用什么版本的管道:

    $ python manage.py findstatic stylesheets/application.css.sass
    No matching file found for 'stylesheets/application.css.sass'.
    

    这只是意味着 django-staticfiles 配置错误,一旦你弄清楚了,管道应该可以正常工作。

    静态文件存储在哪里?在每个应用程序的static 目录中,还是整个项目的目录中?

    【讨论】:

    • 它存储在{project dir}/assets 下整个项目的静态目录中。
    • 您不能将静态文件存储在STATIC_ROOT 中,staticfiles 应该对此发出警告。
    • 太棒了!我将静态根更改为公共并且 findstatic 现在可以正常工作,最新的 django-pipeline 也是如此。谢谢cyberdelia!
    猜你喜欢
    • 2021-08-27
    • 2014-11-10
    • 2011-08-26
    • 2020-06-22
    • 2021-08-16
    • 2020-06-20
    • 2019-06-24
    相关资源
    最近更新 更多