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)
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。