import os
from django.http import HttpResponse
from django.views import View
class MyDownloadView(View):
def get(self, request):
# code etc..
zipfile_path = "/path/to/generated/zipfile.zip" # Replace with the actual path
# Open the file for reading and serve it to the user
with open(zipfile_path, 'rb') as file:
response = HttpResponse(file.read(), content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename="downloaded.zip"'
# Delete the zipfile from the server
os.remove(zipfile_path)
return response
1条答案
按热度按时间lstz6jyr1#
也许你可以这样尝试: