[英]Parse Django JsonResponse with Angular 4
我正在使用Django发送JsonResponse。 如果我将response.json()映射为Angular,则会返回我无法处理的错误。 此外,如果我使用response.text()可视化数据,它将返回如下内容:
响应:{u'foo':u'bar',u'title':u'hello world'}
在Angular 4中,我有以下代码:
return this._http.post(this.serverUrl, JSON.stringify(data), {headers: headers})
.map((response:Response) => response.json())
.catch(this.handleError);
在Django Python中,我有以下代码:
response= {'foo': 'bar', 'title': 'hello world'}
return JsonResponse(response, safe=False);
我也尝试过这个:
return HttpResponse(json.dumps(response), content_type='application/json; charset=utf-8',)
return HttpResponse(json.dumps(response))
return json.dumps(response)
return response
from django.http import JsonResponse
def profile(request):
data = {'foo': 'bar', 'title': 'hello world'}
return JsonResponse(data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.