JsonResponse是HttpResponse的子类, 专门用来生成JSON编码的响应.
from django.http import JsonResponse
response = JsonResponse({"foo": "bar"})
print(response.content)
默认只能传递字典类型, 如果要传递非字典类型需要设置一下safe关键字参数.
response = JsonResponse([1, 2, 3], safe=False)
JsonResponse是HttpResponse的子类, 专门用来生成JSON编码的响应.
from django.http import JsonResponse
response = JsonResponse({"foo": "bar"})
print(response.content)
默认只能传递字典类型, 如果要传递非字典类型需要设置一下safe关键字参数.
response = JsonResponse([1, 2, 3], safe=False)