当前位置: 首页>>代码示例>>Python>>正文


Python FileResponse.headers['Content-disposition']方法代码示例

本文整理汇总了Python中pyramid.response.FileResponse.headers['Content-disposition']方法的典型用法代码示例。如果您正苦于以下问题:Python FileResponse.headers['Content-disposition']方法的具体用法?Python FileResponse.headers['Content-disposition']怎么用?Python FileResponse.headers['Content-disposition']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.response.FileResponse的用法示例。


在下文中一共展示了FileResponse.headers['Content-disposition']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: zip_response_adv

# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-disposition'] [as 别名]
def zip_response_adv(request, filename, files):
    """Return a Response object that is a zipfile with name filename.

    :param request: The request object.
    :param filename: The filename the browser should save the file as.
    :param files: A list of tupples mapping 
        (type, name in zip, filepath or content) 
        i.e.
        ('file', name in zip, './myfile.txt')
        ('text', name in zip, 'a.out foo bar baz the quick fox jumps over the lazy dog')
        only supported types are 'file' and 'text'
    """
    tmp_file = NamedTemporaryFile()
    try:
        with ZipFile(tmp_file, 'w') as zip_file:
            for type, zip_path, actual in files:
                if type == "file":
                    zip_file.write(actual, zip_path)
                else:
                    zip_file.writestr(zip_path, actual)
        tmp_file.flush()  # Just in case
        response = FileResponse(tmp_file.name, request=request,
                                content_type=str('application/zip'))
        response.headers['Content-disposition'] = ('attachment; filename="{0}"'
                                                   .format(filename))
        return response
    finally:
        tmp_file.close() 
开发者ID:ucsb-cs,项目名称:submit,代码行数:30,代码来源:helpers.py


注:本文中的pyramid.response.FileResponse.headers['Content-disposition']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。