Python Django管道没有';不加载资产
我已经跟随做了一个示例项目。文件的结构是:Python Django管道没有';不加载资产,python,django,django-pipeline,Python,Django,Django Pipeline,我已经跟随做了一个示例项目。文件的结构是: - mysite - mysite - __init__.py - settings.py - urls.py - wsgi.py - polls - migrations - templates - polls.html - static - script.j
- 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
一切都很好,但问题是如何使用管理资产。我已经按照下面的代码配置了我的项目,但是它没有正确加载资源
设置.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',
}
}
INSTALLED_APPS = (
.
.
'django.contrib.staticfiles',
'pipeline',
'polls',
)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE = {
'CSS_COMPRESSOR': 'pipeline.compressors.cssmin.CSSMinCompressor',
'CSSMIN_BINARY': 'cssmin',
'JS_COMPRESSOR': 'pipeline.compressors.slimit.SlimItCompressor',
'STYLESHEETS': {
'pollsX': {
'source_filenames': (
'style.css',
),
'output_filename': 'css/styles1.css',
'variant': 'datauri',
},
},
'JAVASCRIPT': {
'pollsX': {
'source_filenames': (
'script.js',
),
'output_filename': 'js/scripts1.js',
},
}
}
polls.html
{% load compressed %}
{% compressed_css 'pollsX' %}
<div class='red-me'>
<h1> Hi! I'm a templ! </h1>
</div>
{% load pipeline %}
{% stylesheet 'pollsX' %}
{% javascript 'pollsX' %}
<div class='red-me'>
<h1> Hi! I'm a templ! </h1>
</div>
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
,但没有成功。我错过什么了吗
Python-3.4和Django-1.7我认为您拼错了css文件名。 而不是使用:
<link href="/static/styles1.css" rel="stylesheet" type="text/css" />
使用:
Django pipline更新非常频繁,因此您的特定教程已经过时。 但我还是想回答你的问题,因为我刚刚花了几个小时用新管道解决了同样的问题,我想与大家分享我的解决方案,并希望它能对其他人有所帮助 一切都适用于:
- Django==1.9.1
- django管道==1.6.4
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',
}
}
INSTALLED_APPS = (
.
.
'django.contrib.staticfiles',
'pipeline',
'polls',
)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
)
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE = {
'CSS_COMPRESSOR': 'pipeline.compressors.cssmin.CSSMinCompressor',
'CSSMIN_BINARY': 'cssmin',
'JS_COMPRESSOR': 'pipeline.compressors.slimit.SlimItCompressor',
'STYLESHEETS': {
'pollsX': {
'source_filenames': (
'style.css',
),
'output_filename': 'css/styles1.css',
'variant': 'datauri',
},
},
'JAVASCRIPT': {
'pollsX': {
'source_filenames': (
'script.js',
),
'output_filename': 'js/scripts1.js',
},
}
}
polls.html
{% load compressed %}
{% compressed_css 'pollsX' %}
<div class='red-me'>
<h1> Hi! I'm a templ! </h1>
</div>
{% load pipeline %}
{% stylesheet 'pollsX' %}
{% javascript 'pollsX' %}
<div class='red-me'>
<h1> Hi! I'm a templ! </h1>
</div>
{%load pipeline%}
{%stylesheet'pollsX%}
{%javascript'轮询“%”
你好我是圣堂武士!
嗨!运行colletstatic
后,是否生成styles1.css
?有问题的最新消息吗?是的,有问题。问题出现在模式DEBUG=False
中。它不从收集的静态文件加载styles1.css
。当pipeline_ENABLED=TrueI指的是潜在的打字错误时,{%load pipeline%}和{%javascript'homejs%}将自动加载压缩文件名。与压缩文件名无关。