我正在使用django-pipeline来缩小js& js和css的版本控制。我非常清楚Debug = False和allow_hosts = [' *']所以不是这里的情况。 奇怪的是,我在8页的2页中得到500服务器错误。 在使用的css和js方面,页面几乎相同(js / css中有几个在那里,但这对我来说似乎不是问题)。我得到500服务器错误的2个页面正在使用谷歌地图,但即使我删除谷歌地图呼叫,问题仍然是相同的。 settings.py文件包含:
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ['*']
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'pipeline.finders.PipelineFinder',
)
PIPELINE_CSS = {
'style': {
'source_filenames': (
'css/style.css',
),
'output_filename': 'css/style.min.css',
}
}
PIPELINE_JS = {
'jquery-util': {
'source_filenames': (
'js/jquery.min.js',
'js/mousewheel.js',
'js/jquery-ui-1.9.2.custom.min.js',
'js/jquery-ui-1.9.2.custom-datepicker.min.js',
'js/datepickr.js',
'js/mscrollbar.min.js',
'js/jqtransform.js',
'js/dropdownchecklist.js',
'js/tooltipster.min.js',
'js/jquery.colorbox-min.js',
'js/nouislider.min.js',
'js/unslider.js',
'js/flexslider.js',
'js/base64.min.js',
'js/intro.js',
),
'output_filename': 'js/jquery-util.min.js',
},
'map-util': {
'source_filenames': (
'js/epolys.js',
'js/arc.js',
'js/arrow.js',
'js/map.js',
),
'output_filename': 'js/map-util.min.js',
},
'common-fb': {
'source_filenames': (
'js/common.js',
'js/fb.js',
),
'output_filename': 'js/common-fb.min.js',
},
'home': {
'source_filenames': (
'js/home.js',
),
'output_filename': 'js/home.min.js',
},
'results': {
'source_filenames': (
'js/results.js',
),
'output_filename': 'js/results.min.js',
},
'planning': {
'source_filenames': (
'js/planning.js',
),
'output_filename': 'js/planning.min.js',
},
'account': {
'source_filenames': (
'js/account.js',
),
'output_filename': 'js/account.min.js',
}
}
PIPELINE_DISABLE_WRAPPER = True
PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor'
PIPELINE_YUGLIFY_BINARY = '/usr/local/bin/yuglify'
PIPELINE_YUI_BINARY = 'yui-compressor'
我花了4个多小时进行调试但到目前为止没有任何帮助。有人可以告诉我这里可能存在什么问题。
P.S。我已将{%load compressed%}添加到所有模板中,因此这也不是问题。
答案 0 :(得分:2)
奇怪的问题有一个奇怪的解决方案。
在用墙撞了这么多个小时之后,我能够找到原因和解决办法,但理由对我来说绝对不是很清楚。
当我完全删除“body”标签内的内容时,我没有得到500错误,所以我开始添加小块的内容。我发现,当代码中有一个注释部分时,它会产生500错误,但是在添加几行代码后,注释不会导致问题。所以我开始玩评论部分,我找到了原因:
<!-- <div class="abc">
<img class="bcd" src="{% static 'images/title.jpg' %}">
<h2 class="xyz">Title</h2>
</div> -->
上面的代码将导致由于
引起的500错误{% static 'images/title.jpg' %}
如果从评论中删除,则500错误消失。这似乎是django / django-pipeline的一个错误。
奇怪的事实是
<!-- <script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script> -->
不会导致500错误。
如果有人知道这个推理,请告诉我。
后来我发现这是由于丢失的文件造成的。当debug设置为True时,静态模板标记只是放置静态根路径,但是当debug设置为False时,管道会尝试替换导致问题的不可用文件的版本控制(添加了哈希)文件。因此,我们必须确保所有静态模板标记在生产中都具有有效的文件路径(debug = False)。