4

我为此奋斗了几个小时,请帮我解决这个问题或杀了我=(

我正在查看所有 4 个文件的 404。任何地方都没有编译文件。

virtualenv 中的 Python 3.4.0,Django 1.7 RC3。

顺便提一句:

python manage.py collectstatic

将所有内容从 assets 复制到 assets_compressed,并在那里添加管理样式。但是最后有一个错误:

ValueError: The joined path (/) is located outside of the base path component (/home/val/Programming/Django/nedviga/nedviga/assets)

设置:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'pipeline',
)

...

STATIC_URL = '/assets/'

STATIC_ROOT = os.path.join(BASE_DIR, 'assets_compressed')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'assets'),
)

...

PIPELINE_ENABLED = True

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'

PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'

PIPELINE_COMPILERS = (
    'pipeline.compilers.less.LessCompiler'
)

PIPELINE_CSS = {
    'libs': {
        'source_filenames': (
            'libs/bootstrap/css/bootstrap.min.css'
        ),
        'output_filename': 'css/libs.css'
    },
    'site': {
        'source_filenames': (
            'main.less'
        ),
        'output_filename': 'css/main.css'
    }
}

PIPELINE_JS = {
    'libs': {
        'source_filenames': (
            'libs/jquery/jquery-2.1.1.min.js'
            'libs/bootstrap/js/bootstrap.min.js'
        ),
        'output_filename': 'js/libs.js'
    },
    'site': {
        'source_filenames': (
            'main.js'
        ),
        'output_filename': 'js/main.js'
    }
}

目录结构:

project_name

    assets
        libs
            ...
        main.js
        main.less

    assets_compressed
        *empty*

    project_name
    manage.py

看法:

<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>AAARGH</title>

    {% load compressed %}
    {% compressed_css 'libs' %}
    {% compressed_css 'site' %}
</head>

<body>

    {% compressed_js 'libs' %}
    {% compressed_js 'site' %}
</body>

</html>
4

2 回答 2

2

您需要在每个 source_filenames 之后加上逗号。即使它只有 1 个来源。

例如: 'source_filenames': ( 'main.less' , ),

不是

'source_filenames': ( 'main.less' ),

于 2015-08-08T12:25:20.297 回答
0

我不知道它是否仍然有用,但您只是忘记将 'pipeline.finders.PipelineFinder' 添加到您的 STATICFILES_FINDERS :

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',
)
于 2015-03-24T17:37:15.220 回答