[英]Django, How to allow users to download a Python generated file
I am new to Django and have a few questions. 我是Django的新手并且有一些问题。
I made a python program that requires user input, and a docx file. 我制作了一个需要用户输入的python程序和一个docx文件。 How do I allow that user to download their generated docx file?
如何允许该用户下载他们生成的docx文件? I am assuming I am going to have to work with temporary files since the program can not overwrite an existing docx file if there are multiple users on the site.
我假设我将不得不使用临时文件,因为如果网站上有多个用户,程序无法覆盖现有的docx文件。
Thanks for your help. 谢谢你的帮助。
Write the response with "Content-Type: application/octet-stream" and "Content-Disposition: attachment". 使用“Content-Type:application / octet-stream”和“Content-Disposition:attachment”编写响应。 Then write the updated file to the response.
然后将更新的文件写入响应。
For more exact mime types, check out: What is a correct mime type for docx, pptx etc? 有关更精确的mime类型,请查看: docx,pptx等的正确mime类型是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.