【发布时间】:2015-08-13 09:55:48
【问题描述】:
如何返回 JSON 响应和文件响应:
现在我这样做:
runNumber = "A0001"
response = None
try:
response = make_response("Line One\r\nLine Two\r\n")
response.headers["Content-Disposition"] = "attachment; filename=" + runNumber + ".txt"
except MyCustomException as e:
response = jsonify(error=e.value, runnumber=runNumber)
except:
raise
return(response)
但这仅允许我返回 JSON 或文件。在某些情况下,我想同时退货。
[编辑:] 我想返回 JSON 和文件的情况是当有一个关于文件内容的警告时,用户应该在使用文件之前检查。
如果这不可能,我会将警告添加到文件的内容中。
【问题讨论】:
-
客户端如何将文件和 JSON 部分再次分离出来?