python - django 中的 JsonResponse 和 HttpResponse 有什么区别

标签 python django

让我们说 result = {'a': 1, 'b': 2, 'c': 3}
这两者有区别吗:

return HttpResponse(json.dumps(a))


return JsonResponse(a)

最佳答案

doc状态,主要区别是

  • 自动序列化
  • 正确的内容类型
  • 默认情况下更安全的输入检查
  • 关于python - django 中的 JsonResponse 和 HttpResponse 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54628815/

    相关文章:

    python - 使用不同的 botocore 安装 Boto3

    python - 自引用类 : concrete python class from C interface

    python - 如何让 DjangoModelFactory 创建模型而不将其保存到数据库?

    python - 使用 dask 合并 csv 文件

    python - Flask 的错误请求

    python - 如何将 url 路由到 Django 和 DRF 类的特定方法

    python - 尝试访问 Django 页面时,在 Heroku 上部署 Django 应用程序时出现错误代码 H13

    可用项目的 Django ListView 查询集

    python - 关于 python 中的 GIL

    python - 使用 tox 创建的虚拟环境无法使用 pip install