Answer the question
In order to leave comments, you need to log in
How to return a file for download from Django?
Hello.
There is a .zip archive in a certain directory, you need to return the file for download when you access the link through the blizzard.
I do this:
def download_file(request):
response = HttpResponse(open("test.zip"), content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=test.zip'
response['Content-Type'] = 'application/x-zip'
return response
Answer the question
In order to leave comments, you need to log in
django x-accel-redirect
stackoverflow.com/questions/28704712/django-nginx-...
server {
listen 27796;
server_name myurl.com;
root /home/ucwsri/webapps/static_media_ucwsri_nginx;
location / {
autoindex on;
}
location ^~ /protected/ {
internal;
}
response = HttpResponse()
url = "/protected/some-file.pdf"
response['X-Accel-Redirect'] = url
return response
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question