Django return text file download






















How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. Asked 5 years, 3 months ago. Active 1 month ago. Viewed 35k times. ODFTemplate 'test.

How do I make it start downloading as file instead? Improve this question. This still has the same problem. Django 1. File instead of FileWrapper works for me. Sign up or log in Sign up using Google. Sign up using Facebook.

Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. The download option is a general requirement for any website like the online book, free application software, free games, etc. The file can be downloaded after executing a particular URL or clicking the download link and getting permission from the user. The ways of downloading a text file without any download link and a PDF file using the download link in the Django app will be shown in this tutorial.

Prerequisites: Before practicing the script of this tutorial, you have to complete the following tasks. Setup a Django App: Run the following command to create a Django app named downloadapp. Import mimetypes module import mimetypes import os module import os Import HttpResponse module from django. Have you considered just sending p. Maybe it would be better to use StreamingHttpResponse instead of creating temporary files and X-Sendfile How are we doing?

Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Improve this answer. Would be possible to add a specific filename to the file generated from the content luc?? The 2nd snippet displays the content but no file is served for download — stelios.

I have the same problem. The same works also for render shortcut: return render request, 'file. I agree with luc, however another alternative is to use X-Accel-Redirect header. Interesting answer. Thanks — luc. Good solution and great way to have control on various file types. I have this pattern in one of my url.

I was using a more complex method until recently, then I discovered this and this : path 'file. Unless I'm missing something, this is pretty simple and powerful. Sign up or log in Sign up using Google.



0コメント

  • 1000 / 1000