【问题标题】:NoneType has no attribute 'rfind' when compiling Less with django-pipeline使用 django-pipeline 编译 Less 时,NoneType 没有属性 'rfind'
【发布时间】:2012-05-19 19:15:29
【问题描述】:

我正在尝试使用django-pipeline 编译一些.less 文件。当我运行collectstatic 时,所有内容都正确复制,然后出现此错误:

Traceback (most recent call last):
  File "manage.py", line 35, in <module>
    execute_manager(settings)
  File ".../lib/python2.7/site-packages/django/core/management/__init__.py", line 459, in execute_manager
    utility.execute()
  File ".../lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ".../lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File ".../lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File ".../lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File ".../lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
    collected = self.collect()
  File ".../lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 119, in collect
    dry_run=self.dry_run)
  File ".../lib/python2.7/site-packages/pipeline/storage.py", line 26, in post_process
    output_file = packager.pack_stylesheets(package)
  File ".../lib/python2.7/site-packages/pipeline/packager.py", line 90, in pack_stylesheets
    variant=package.variant, **kwargs)
  File ".../lib/python2.7/site-packages/pipeline/packager.py", line 99, in pack
    paths = self.compile(package.paths)
  File ".../lib/python2.7/site-packages/pipeline/packager.py", line 93, in compile
    return self.compiler.compile(paths)
  File ".../lib/python2.7/site-packages/pipeline/compilers/__init__.py", line 34, in compile
    compiled_content = compiler.compile_file(content, finders.find(path))
  File ".../lib/python2.7/site-packages/pipeline/compilers/less.py", line 19, in compile_file
    cwd = os.path.dirname(path)
  File ".../lib64/python2.7/posixpath.py", line 120, in dirname
    i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'

我认为我对 settings.py 中的类型没有做任何奇怪的事情,但为了以防万一,这里有一些相关的内容:

STATICFILES_STORAGE = "pipeline.storage.PipelineCachedStorage"

PIPELINE = True

STATICFILES_DIRS = (
    ("projectname", os.path.join(REPO_ROOT, "static")),
)

PIPELINE_COMPILERS = (
    'pipeline.compilers.coffee.CoffeeScriptCompiler',
    'pipeline.compilers.less.LessCompiler'
)

PIPELINE_JS = {
    'projectname': {
        'source_filenames': ('js/*.coffee',),
        'output_filename': 'projectname/js.js'
    }
}

PIPELINE_CSS = {
    'projectname': {
        'source_filenames': ('css/style.less',),
        'output_filename': 'projectname/css.css'
    }
}

如果我用 glob(即css/*.less)替换我的 CSS source_filenames,我会得到相同的结果。该文件绝对是我要告诉它的位置(至少,如果我用我知道错误的路径替换它,我会得到一个不同的错误)。注释掉 PIPELINE_CSS 行后,我的 CoffeeScript 可以很好地编译为 JS。有什么想法吗?

【问题讨论】:

    标签: django less nonetype


    【解决方案1】:

    你可以尝试运行这个吗:

    $ python manage.py findstatic css/style.less

    如果你有这个结果:

    No matching file found for 'css/style.less'.

    你可能配置错误staticfiles,否则也请告诉我。

    【讨论】:

    • 原来因为我在STATICFILES_DIRS 中为我的站点静态文件提供了命名空间projectname,所以我需要将source_filenames 设置为('projectname/css/style.less',)。很奇怪,因为 JS 在同一个地方,但它只能在路径中没有 projectname 工作。去图吧。
    • 我遇到了同样的错误,但在我的情况下,它没有指定 output_filename。希望这可以帮助遇到这个问题的人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-01
    • 1970-01-01
    • 2016-09-12
    • 2021-08-03
    • 2018-12-25
    • 1970-01-01
    相关资源
    最近更新 更多