开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜