Django: Вывод CSV с помощью JsonResponse
def export_csv(request,query):
p = Path(os.path.dirname(__file__))
FILE_JUDGEMENT = str(p.parent)+"/static/pygiustizia"
content = ""
res = {}
res["status"] = "ok"
res["data"] = content
response = JsonResponse(res, status=200)
if os.path.exists(nameFile):
response["Content-Description"] = "File Transfer"
response["Content-Type"] = "application/octet-stream"
response["Content-Disposition"] = 'attachment; filename="somefilename.csv"'
response["Expires"] = 0
response["Cache-Control"] = "must-revalidate"
response["Pragma"] = "public"
writer = csv.writer(response,delimiter =';')
writer.writerow(headerData.values())
totalRowData = 0
#fdata = toDict(fdata)
#print("fdata",fdata)
for keyRow,valueRow in fdata.items():
#print("valueRow",valueRow.values())
writer.writerow(valueRow.values())
totalRowData = totalRowData + 1
return response
У меня есть контроллер-view в python django framework.
Моя цель - вывести и загрузить csv, созданный по запросу данных из elastisearch.
он создает somefilename.csv, но в заголовке csv файла у меня
{"status": "ok", "data": ""}sendername;controparte;nomegiudice;annosentenza;codiceufficio;fascicoloprecedente_annoruolo;
Почему?