我已经按照本教程制作了一个示例项目。文件的结构是:
- mysite
- mysite
- __init__.py
- settings.py
- urls.py
- wsgi.py
- polls
- migrations
- templates
- polls.html
- static
- script.js
- style.css
- admin.py
- models.py
- tests.py
- urls.py
- views.py
- manage.py
一切正常,但是问题在于使用Django-pipeline来管理资产。我已将我的项目配置为与以下代码相同,但它没有正确加载资产。
设置.py
INSTALLED_APPS = (
.
.
'django.contrib.staticfiles',
'pipeline',
'polls',
)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
PIPELINE_ENABLED = True
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.cssmin.CSSMinCompressor'
PIPELINE_CSSMIN_BINARY = 'cssmin'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.slimit.SlimItCompressor'
PIPELINE_CSS = {
'pollsX': {
'source_filenames': (
'style.css',
),
'output_filename': 'styles1.css',
'variant': 'datauri',
},
}
PIPELINE_JS = {
'pollsX': {
'source_filenames': (
'script.js',
),
'output_filename': 'scripts1.js',
}
}
民意调查.html
{% load compressed %}
{% compressed_css 'pollsX' %}
<div class='red-me'>
<h1> Hi! I'm a templ! </h1>
</div>
样式.css
.red-me {
color: red;
}
生成的输出http://127.0.0.1/polls
为
<link href="/static/styles1.css" rel="stylesheet" type="text/css" />
<div class='red-me'>
<h1> Hi! I'm a templ! </h1>
</div>
它无法/static/styles1.css
在浏览器中加载文件。甚至,我测试./manage.py collectstatic
没有任何成功。我错过了什么?
Python-3.4 和 Django-1.7