ich habe einen Problem: ich habe meinen Code etwas umgebaut und jetzt bekomme ich eine Fehlermeldung, kann den Fehler aber nicht finden. Deshalb brauche ich eure Hilfe! Hier mal der Code:
Hier der View
Code: Alles auswählen
def query(request):
results = []
ctx = {'added': count,
'type': type,
'limit': limit}
return SearchResponse(results, ctx)
Code: Alles auswählen
class SearchResponse(HttpResponse):
def __init__(self, items, ctx, id='id'):
self.items = items
self.ctx = ctx
self.id = id
self.num_rows = len(items)
HttpResponse.__init__(self,
content=self.serialize(),
mimetype="application/json")
self['Pragma'] = "no-cache"
self['Cache-Control'] = "must-revalidate"
def serialize(self):
items = json_encode(self.items)
ctx = {}
for k, v in self.ctx.iteritems():
ctx[k] = json_encode(v)
return(self.dojo(items, ctx))
def dojo(self, items, ctx):
dojo = """{
"identifier": "%s",
"label": "%s",
"numRows": "%s",
"items": %s,\n""" % (self.id, self.id, str(self.num_rows), items)
dojo += ',\n'.join(""" "%s": %s""" % (k, v) for k, v in ctx.iteritems())
dojo += '\n}'
return dojo
Was ich geändert habe: der SearchResponse def hatte vorher mehrere Parameter. Das was in ctx steht liess sich vorher als einzelne Parameter angeben, jetzt etwas komfortabler als dict. Das was er in der Variable dojo zusammenbaut sieht soweit ganz gut aus, ich habe es mir mal ausgeben lassen.
Jetzt die Fehlermeldung:
Code: Alles auswählen
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 282, in __call__
response_headers = [(str(k), str(v)) for k, v in response.items()]
TypeError: 'list' object is not callable
[30/Jul/2012 11:22:27] "POST /shop/searchquery/ HTTP/1.1" 500 576
Hoffe Ihr könnt mir helfen!
MfG ready