我有一个Django视图,它返回JSON格式的设置配置文件。当我在浏览器中获取它时它工作正常。但是当我尝试获取与其链接的Backbone Collection时,它返回500并显示以下错误消息:“'list'对象没有属性'find'”。
堆栈跟踪:
/usr/lib/python2.7/ConfigParser.py in _interpolate_some
_interpvar_re = re.compile(r"%\(([^)]+)\)s")
def _interpolate_some(self, option, accum, rest, section, map, depth):
if depth > MAX_INTERPOLATION_DEPTH:
raise InterpolationDepthError(option, section, rest)
while rest:
p = rest.find("%") <-- where the stacktrace leads to
if p < 0:
accum.append(rest)
return
if p > 0:
accum.append(rest[:p])
rest = rest[p:]
无头配置阅读器:
class SectionlessConfig():
def __init__(self, fp):
self.fp = fp
self.sechead = "[root]\n"
def readline(self):
if self.sechead:
try:
return self.sechead
finally:
self.sechead = None
else:
return self.fp.readline()
class Settings():
configuration_file=settings.SHAKEARRAY_CFG_PATH
def __init__(self):
self.parser = ConfigParser.SafeConfigParser()
def get_all_settings(self):
self.parser.readfp(SectionlessConfig(open(Settings.configuration_file)))
return self.parser.items('root')
Django视图代码:
def all_settings(request):
settings_list = seiscomp_settings.get_all_settings()
settings_array = []
for name, value in settings_list:
settings_obj = {}
settings_obj['name'] = name
settings_obj['value'] = value
settings_array.append(settings_obj)
return JsonResponse(settings_array, safe=False)
我不确定Backbone代码是否会提供很多帮助,但仍然是这样。
'use strict';
Shakescreen.module('Settings', function(Settings, App, Backbone) {
Settings.Setting = Backbone.Model.extend({
urlRoot: 'http://localhost:8000/settings',
idAttribute: 'name',
initialize: function() {
console.log('creating setting object');
}
});
Settings.SettingsCollection = Backbone.Collection.extend({
url: 'http://localhost:8000/settings',
model: Settings.Setting,
initialize: function() {
console.log('initialize empy settings collection');
}
});
});
因此,SettingsCollection上的提取返回500,但通过浏览器的GET工作正常(wget也是如此)。有什么提示吗?