1

我正在使用 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 个多小时进行调试,但到目前为止没有任何帮助。谁能告诉我这里可能存在什么问题。

PS 我已将 {% load compressed %} 添加到所有模板中,所以这也不是问题。

4

1 回答 1

3

奇怪的问题有一个奇怪的解决方案。

在用头撞墙这么多小时后,我能够找到原因和解决方案,但原因对我来说绝对不是很清楚。

当我完全删除“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)。

于 2014-05-28T09:59:50.297 回答