Return a downloadable file link given a string with Django
Given a URL string which points to a file on my local nginx instance, how do I ma开发者_如何学编程ke Django return a response that causes the file to be downloaded from nginx? I don't want Django to be opening up the file and streaming it.
Use the X-Accel-Redirect
header: http://wiki.nginx.org/XSendfile
For example:
resp = HttpResponse()
resp['X-Accel-Redirect'] = "/static/my_file"
return resp
Note that, as per the documentation, you'll need to translate the local path into a URL which nginx can serve.
精彩评论