一、传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)
django HttpResponse的用法
原文地址:https://www.cnblogs.com/di2wu/p/10068528.html