我有以下基于类的视图,当我发出 ajax 请求时,我收到“模块”对象不可调用错误
/?id=145
有任何想法吗 ?
class CityList(ListView):
template_name = "profile/profile.html"
model = City
def render_to_response(self, context, **response_kwargs):
if self.request.is_ajax() and self.request.GET.get('query'):
query = self.request.GET.get('query')
city_filter = [{'name': i.name,
'id': i.id}
for i in City.objects.filter(
name__icontains=query)]
results = city_filter
return HttpResponse(json.dumps(results),
mimetype='application/json')
elif self.request.GET.get('id'):
query = self.request.GET.get('id')
if query:
return HttpResponse(json.dumps(list(self.object_list.filter(
id=query).values('name', 'id')
)), mimetype='application/json')