一、传json字典
def back_json(rquest):#JsonResponse父类是HttpResponse,原码里调用了json.dumps()from django.http import JsonResponseback_msg = {'name':name,'age':123}return JsonResponse(back_msg)
二、传列表
def back_json(rquest):#JsonResponse父类是HttpResponse,原码里调用了json.dumps()from django.http import JsonResponseback_list = [1,2,3]#JsonResponse默认传字典,传列表的话需要指定safe=Falsereturn JsonResponse(back_list,safe=False)