【问题标题】:serve json file to user in django在 django 中向用户提供 json 文件
【发布时间】:2017-03-18 07:47:07
【问题描述】:

如何向用户提供 JSON 文件? 目前我有一个我希望用户下载的 JSON 对象。

我试过了:

res = HttpResponse(json_data, content_type='application/json')
res['Content_disposition'] = 'attachment; filename=result.json'

但它仍然在浏览器中提供 json,而不是让用户下载它。

【问题讨论】:

  • 以下答案解决了您的问题吗?

标签: json django


【解决方案1】:

摘自官方docs

response = HttpResponse(json_data, content_type='application/json')
response['Content-Disposition'] = 'attachment; filename="result.json"'

【讨论】:

  • 和我试过的一样,但它在浏览器中提供 json 而不是有下载弹出窗口。
猜你喜欢
  • 2014-06-09
  • 2012-07-05
  • 2014-07-11
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-31
  • 2015-10-23
相关资源
最近更新 更多