python下载大文件-python-Django:允许用户下载大文件

我正在建立一个私人文件上传网站.爱丽丝上传文件,鲍勃下载文件.

除了Alice和Bob之外的其他人不应具有访问权限.我最初是在考虑为文件提供一个复杂的名称(http://domain/download/md5sum.zip),但是我想要一个有效的链接.因此,例如http://domain/download/tempkey/aaa123/file.zip.这将使我对文件下载和日志记录有更多控制.

class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):

def do_GET(self):

# The URL the client requested

print self.path

# analyze self.path, map the local file location...

# open the file, load the data

with open('test.py') as f: data = f.read()

# send the headers

self.send_response(200)

self.send_header('Content-type', 'application/octet-stream') # you may change the content type

self.end_headers()

# If the file is not found, send error code 404 instead of 200 and display a message accordingly, as you wish.

# wfile is a file-like object. writing data to it will send it to the client

self.wfile.write(data)

但是,如何在Django中使用它呢?视图函数应该返回一个HTTPResponse对象,但不会这样做.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值