python - django-pipeline js 压缩器不工作

标签 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',
    }
}

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

最佳答案

你有没有运行./manage.py collectstatic --noinput

如果这不起作用,请确保这些在您的 settings.py 中并再次运行 collectstatic,您的 Assets 将在 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',
)

然后您可以通过将以下内容放入您的模板中来使用您的 Assets :

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

希望对您有所帮助。

关于python - django-pipeline js 压缩器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21426849/

相关文章:

css - Django 管道、Heroku 和 SASS

python - 如何在 Pycharm 中启用自动缩进?

python - openerp 7 无法渲染 View

python - 在 RedShift 中使用 Django 多数据库

python - 从 django.utils.importlib 导入 import_module 导入错误 : No module named importlib

python - 使用 Django/Python : ModuleNotFoundError: No module named 'pages' 创建初学者应用程序

Python 问题 : TypeError: unhashable type: 'slice' during web scraping

python - 为 CustomUser 指定的未知字段(密码 1、密码 2)

当 DEBUG=False 时 django 管道会中断管理

python - Django 1.8.2 不提供所有静态文件 - django-pipeline