我使用django-pipeline来简化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个多小时进行调试,但到目前为止没有任何帮助。谁能告诉我这里可能出现的问题是什么?
附言:我已经在所有的模板中添加了{% load compressed %},所以这也不是问题。
发布于 2014-05-28 17:59:50
这个奇怪的问题有一个奇怪的解决方案。
在用头撞墙这么多小时后,我终于找到了原因和解决方案,但我完全不清楚其中的原因。
当我完全删除"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的一个bug。
奇怪的事实是
<!-- <script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script> -->不会导致500错误。
如果有人知道这是怎么回事,请告诉我。
更新
后来我发现这是由于文件丢失造成的。当debug设置为True时,静态模板标记只是放置静态根路径,但当debug设置为False时,管道会尝试替换导致问题的不可用文件的版本控制(添加了散列)文件。因此,我们必须确保所有静态模板标记在生产环境中都具有有效的文件路径(debug=False)。
https://stackoverflow.com/questions/23900041
复制相似问题