我正在尝试 django-pipeline 以缩小静态资源,为它们使用缓存并使我的模板更简单。我的浏览器找到并加载了我的 CSS 和 JS 文件,但我的(非常简单的)主页加载大约需要 10 秒。
我正在使用 Python 2.7.6、Django 1.7.3 和 django-pipeline 1.4.3。PyCharm 使用本地 virtualenv 运行开发服务器。
我的 settings.py 包含以下内容:
DEBUG = True
TEMPLATE_DEBUG = DEBUG
INSTALLED_APPS = (
'django_admin_bootstrapped', # custom admin
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# pip installed apps
'pipeline',
# project apps
'myapp',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'pipeline.middleware.MinifyHTMLMiddleware',
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.FileSystemFinder',
'pipeline.finders.CachedFileFinder',
'pipeline.finders.PipelineFinder',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'myapp/static'),
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'
PIPELINE_CSS = {
'base': {
'source_filenames': (
'myapp/css/base.css',
'myapp/bower_components/bootstrap/dist/css/bootstrap.css',
'myapp/bower_components/Hover/css/hover.css',
'myapp/bower_components/font-awesome/css/font-awesome.css',
),
'output_filename': 'css/myapp.css',
},
}
PIPELINE_JS = {
'base': {
'source_filenames': (
'myapp/bower_components/jquery/dist/jquery.min.js',
'myapp/bower_components/bootstrap/dist/js/bootstrap.min.js',
),
'output_filename': 'js/myapp.js',
},
}
我的基本 HTML 模板包含以下内容:
{% load staticfiles %}
{% load pipeline %}
<!DOCTYPE html>
<html>
<head>
[...]
{% block css %}
{% stylesheet 'base' %}
{% endblock css %}
{% block javascript %}
{% javascript 'base' %}
{% endblock javascript %}
</head>
<body> [...] </body>
</html>
我的 home.html 扩展了 base.html 但不使用 css 或 javascript 管道的模板标签。
只是为了确保 yuglify 可用:
$ yuglify --version
0.1.4
我在这里做错了什么?
注意:如果PIPELINE_ENABLED = True
.