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


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

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


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

示例1: mapprint

# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Type'] [as 别名]
def mapprint(request):
    payload = request.json_body

    output_file_name = MapPrint(payload).print_pdf()

    response = FileResponse(
        output_file_name,
        request=request
    )
    response.headers['Content-Disposition'] = ('attachement; filename="{}"'
                                               .format(output_file_name + '.pdf'))
    response.headers['Content-Type'] = 'application/pdf'

    if os.path.exists(output_file_name):
        os.remove(output_file_name)

    return response
开发者ID:ioda-net,项目名称:geo-pyprint,代码行数:19,代码来源:__init__.py

示例2: files_list_view

# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Type'] [as 别名]
    def files_list_view(self):
        if not 'password' in self.request.POST and self.check():
            print self.request.POST
            return HTTPFound(location='/login')
        url = USB_LOCATION + get_url(self.request.matchdict['list'])
        url_parsed = '/'
        for i in range(len(url.split('/')) - 3):
            url_parsed += url.split('/')[i + 1] + '/'
        action = url.split('/')[-2]
        filename = str(url_parsed.split('/')[-2])
        if 'password' in self.request.POST:
            if self.request.POST['password'] != '':
                password = self.request.POST['password']
#                print password
                content = encrypt(self.request.POST['notecontent'], password)
                write('/'.join(url.split('/')[:-2]), content)
                return HTTPFound(location='/files' + url[:-1])
#                return Response()
        elif 'file' in self.request.POST:
            filename = self.request.POST['file'].filename
            print filename
            input_file = self.request.POST['file'].file
            upload(input_file, url, filename)
            print '/files' + url
            return HTTPFound(location='/files' + url)
        elif 'dir_name' in self.request.POST:
            dirname = self.request.POST['dir_name']
            make_dir(dirname, url)
            return HTTPFound(location='/files' + url)
        elif 'note_name' in self.request.POST:
            write(url + self.request.POST['note_name'], '')
            return HTTPFound(location='/files' + url)
        elif 'notecontent' in self.request.POST:
            content = encrypt(self.request.POST['notecontent'], decrypt(self.request.session['enpass'], self.request.cookies['r']))
            write('/'.join(url.split('/')[:-2]), content)
            return HTTPFound(location='/files' + url)
        elif action == 'edit':
            content = decrypt(read(url_parsed[:-1]), decrypt(self.request.session['enpass'], self.request.cookies['r']))
            re = { 'page_title' : 'Notes', 'edit' : True, 'contents' : content, 'url' : url }
            re.update(self.get_header())
            return re
        elif action == 'rename':
            # file_old = str(url_parsed.split('/')[-3])
            file_old = '/'.join(url_parsed.split('/')[:-2])
            if not is_file('/'.join(url_parsed.split('/')[:-2])) and not is_dir('/'.join(url_parsed.split('/')[:-2])):
                print 'not filename'
                return HTTPFound(location='/files')
            rename(file_old, filename)
            return HTTPFound('/files' + '/'.join(url.split('/')[:-4]))
        elif is_file(url_parsed[:-1]):
            if action == 'download':
                re = FileResponse(url_parsed[:-1])

                re.headers['Content-Disposition'] = 'attachment; filename="' + filename + '"'
                re.headers['Content-Type'] = 'application/force-download'
#                re.headers['filename'] = filename
                re.headers['Accept-Ranges'] = 'bytes'
                return re
            elif action == 'delete':
                delete(url_parsed[:-1])
                return HTTPFound(self.request.url[:-7-len(filename.replace(' ', '%20'))])
        elif is_dir(url[:-7]) and action == 'delete':
            delete(url[:-7])
            return HTTPFound(self.request.url[:-7-len(filename)])
        elif not is_dir(url) or len(url.split('/')) < 5:
            return HTTPFound(location='/files')
        temp = [str(part) for part in list_dir(url)]
        temp.sort(lambda x, y: cmp(x.lower(),y.lower()))
        item_list = [ { 'url' : '/files/' + url[1:] + part if is_dir(url + part) else '/files/' + url[1:] + part + '/download', 'url_ren' : '/files/' + url[1:] + part, 'url_del' : '/files/' + url[1:] + part + '/delete', 'name' : part, 'is_file' : is_file(url + part), 'size' : size(url + part) } for part in temp ]
        
        re = {'page_title': LINKS['files_list']['title'], 'list' : item_list, 'up_dir' : '/files/' + url_parsed[1:], 'url' : url, 'edit' : False }
        re.update(self.get_header())
        return re
开发者ID:theEyeD,项目名称:python,代码行数:75,代码来源:views.py


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