django-pipeline js压缩机无法正常工作

时间:2014-01-29 09:25:29

标签: python django django-pipeline

这是我的settings.py看起来像:

kProjectRoot = abspath(normpath(join(dirname(__file__), '..')))

MEDIA_ROOT = os.path.join(kProjectRoot, 'abc/media/')

MEDIA_URL = '/media/'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',

    'south',
    'xlrd',
    'pipeline',
    )

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

PIPELINE_YUI_BINARY='C:/Python27/Lib/site-packages/yuicompressor-2.4.8-py2.7.egg/yuicompressor'

PIPELINE_JS = {
    'site': {
    'source_filenames': (
        'media/js/zk.base.js',
        'media/js/zk.popupmenu.js',
        'media/js/zk.tree.js',
        'media/js/zk.treenode.js',
    ),
    'output_filename': 'media/js/script.min.js',
    }
}

我在做什么错误,请指导我。我认为它应该在script.min.js中创建一个media/js/,我可以在templates中加载。{/ p>

2 个答案:

答案 0 :(得分:1)

您运行./manage.py collectstatic --noinput

了吗?

如果这不起作用,请确保这些内容在settings.py中并再次运行collectstatic,您的资源将位于build文件夹下。

PIPELINE_ENABLED = True

STATICFILES_FINDERS = ( 'pipeline.finders.FileSystemFinder', 'pipeline.finders.AppDirectoriesFinder', 'pipeline.finders.PipelineFinder', 'pipeline.finders.CachedFileFinder', )

STATIC_ROOT = normpath(join(SITE_ROOT, 'build'))

STATIC_URL = '/assets/'

STATICFILES_DIRS
STATICFILES_DIRS = (
    normpath(join(SITE_ROOT, 'static')),
)

INSTALLED_APPS = (
    ...
    'django.contrib.staticfiles',
)

然后,您可以通过在模板中添加以下内容来使用您的资源:

{% load compressed %}
{% compressed_js 'site' %}

希望它有所帮助。

答案 1 :(得分:0)

\路径中使用正斜杠/替换反斜杠PIPELINE_YUI_BINARY