一、传json字典

def back_json(rquest):
    #JsonResponse父类是HttpResponse,原码里调用了json.dumps()
    from django.http import JsonResponse
    back_msg = {'name':name,'age':123}
    return JsonResponse(back_msg)

二、传列表

def back_json(rquest):
    #JsonResponse父类是HttpResponse,原码里调用了json.dumps()
    from django.http import JsonResponse
    back_list = [1,2,3]
    #JsonResponse默认传字典,传列表的话需要指定safe=False
    return JsonResponse(back_list,safe=False)