views.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:django-protected-media 作者: cobusc 项目源码 文件源码
def protected_view(request, path, server="django", as_download=False):
    if server != "django":
        mimetype, encoding = mimetypes.guess_type(path)
        response = HttpResponse()
        response["Content-Type"] = mimetype
        if encoding:
            response["Content-Encoding"] = encoding

        if as_download:
            response["Content-Disposition"] = "attachment; filename={}".format(
                basename(path))

        response[server_header(server)] = os.path.join(
            PROTECTED_MEDIA_LOCATION_PREFIX, path
        ).encode("utf8")
    else:
        response = serve(
            request, path, document_root=PROTECTED_MEDIA_ROOT,
            show_indexes=False
        )

    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号