処理が終わったらファイルが落ちてくるようにしたいです。
from docx import Document from docx.shared import RGBColor,Pt from docx.shared import Inches def make_document(request): document = Document() font = document.styles['Normal'].font font.size = Pt(9) p = document.add_heading(level=1) p.alignment = WD_ALIGN_PARAGRAPH.CENTER wp = p.add_run('TITLE') wp.font.size = Pt(22) id = str(uuid.uuid4()) document.save(f"{id}.docx") result = {"id": id} result_str = json.dumps(result, ensure_ascii=False, indent=2) download_file(request) return render(request, 'next.html') def download_file(request): file_id = request.GET.get("file-id", "") response = HttpResponse(open(f"{file_id}.docx", 'rb').read()) response['Content-Disposition'] = 'attachment; filename="contents-certified.docx"' response['Content-Type'] = "application/octet-stream" return response
とコードを書きました。このコードを実行すると、
[Errno 2] No such file or directory: '.docx' とエラーが出ます。作業ディレクトリ内にはファイルは落ちてくるのですが。ダウンロードにファイルが落ちてくるようにするにはどうしたらいいでしょうか?
あなたの回答
tips
プレビュー