Skip to main content
 首页 » 编程设计

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

2025年05月04日26tintown

这是我的 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' %} 

希望对您有所帮助。