简体   繁体   English

Django,如何允许用户下载Python生成的文件

[英]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.

相关问题 如何允许用户使用 python/Flask 下载 excel 文件? - How to allow users to download an excel file using python/Flask? 如何允许用户直接下载存储在 django 中我的媒体文件夹中的文件? - How to allow users to directly download a file stored in my media folder in django? django下载生成的文件 - django download generated file 允许用户直接下载文件 django - Allow users to download files directly django 您如何允许用户通过终端在 Python 脚本中上传 2 个 excel 文件,而不是下载新的文件文件? - How do you allow users to upload 2 excel files in a Python script via terminal, than download a new file file? 允许用户下载在AWS上生成的zip文件 - Allow user to download zip file generated on AWS 如何在 Django 项目中下载使用 python-docx 生成的文档? - How to download a document generated with python-docx in Django project? 如何使用 Django REST 框架返回生成的文件下载? - How to return generated file download with Django REST Framework? 如何通过 nginx 在 Django 中提供生成的文件作为下载? - How do I serve a generated file in Django via nginx as download? 如何允许用户使用Flask下载MIDI文件而不下载0字节? - How do I allow users to download a MIDI file with Flask without getting a 0 byte download?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM