#HttpResponse返回,前端需要进行json解析
#views.py
return HttpResponse(json.dumps({"msg":"我是后端返回的数据,你需要json解析!"}))
#JsonResponse,前端接收的直接是一个对象
#views.py
from django.http import JsonResponse
return JsonResponse({"msg":"我是后端返回的数据,你可以直接使用!"})
#HttpResponse返回,前端需要进行json解析
#views.py
return HttpResponse(json.dumps({"msg":"我是后端返回的数据,你需要json解析!"}))
#JsonResponse,前端接收的直接是一个对象
#views.py
from django.http import JsonResponse
return JsonResponse({"msg":"我是后端返回的数据,你可以直接使用!"})
本文标题:Django返回前端json数据
本文链接:https://www.haomeiwen.com/subject/ciuuprtx.html
网友评论