django-pipeline根本不工作

时间:2014-08-22 23:34:27

标签: python django python-3.x django-pipeline django-1.7

我正在和它斗争几个小时,拜托,帮我解决这个问题或者杀了我=(

我在视图中获得了所有4个文件的404。没有编译过的文件。

virtualenv中的Python 3.4.0,Django 1.7 RC3。

顺便说一下:

python manage.py collectstatic

将所有内容从资产复制到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>

3 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分:0)

最后,我已切换到django-compressor(http://django-compressor.readthedocs.org/en/latest/)。

但我仍然愿意使用django-pipeline

解决所述问题

答案 2 :(得分:0)

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

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