一、传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)

 

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-20
  • 2021-12-18
  • 2020-03-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案