本文整理汇总了Python中pyramid.response.FileResponse.content_type方法的典型用法代码示例。如果您正苦于以下问题:Python FileResponse.content_type方法的具体用法?Python FileResponse.content_type怎么用?Python FileResponse.content_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.FileResponse
的用法示例。
在下文中一共展示了FileResponse.content_type方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_to_moe_view
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import content_type [as 别名]
def export_to_moe_view(request):
import io, re
from tempfile import NamedTemporaryFile
import xlwt
from pyramid_sqlalchemy import Session
from ..models import NewStudentModel
from pyramid.response import FileResponse
with NamedTemporaryFile(delete=True) as f:
wb = xlwt.Workbook()
ws = wb.add_sheet('sheet1')
ws.write(0, 0, '姓名')
ws.write(0, 1, '身分證號')
regex = re.compile(r'^[A-Z]\d{9}$') # 比對是否為身分證號
counter = 1
for each_new_student in Session.query(NewStudentModel).filter(NewStudentModel.status==1):
if regex.match(each_new_student.id_number):
ws.write(counter, 0, each_new_student.name)
ws.write(counter, 1, each_new_student.id_number)
counter += 1
wb.save(f.name)
f.flush()
f.seek(0)
response = FileResponse(f.name)
response.content_type = 'application/octet-stream'
response.content_disposition = 'attachment; filename="moe.xls"'
return response
示例2: __call__
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import content_type [as 别名]
def __call__(self):
params = self.request.params
doc_data = {
'year': params['year'],
'regiontype': params['regiontype'],
'regionid': params['region'],
'selected_sections': params['sections'].split(' '),
'format_dest': 'pdf'
}
root_section = SectionData(self.request.registry.settings['climas.report_section_path'])
da = DocAssembler(
doc_data,
root_section,
settings={
'region_url_pattern': 'http://localhost:8080/regiondata/${region_type}/${region_id}',
'region_data_path_pattern': self.request.registry.settings['climas.region_data_path'] + '/${region_type}/${region_id}',
'section_debug': False
},
)
with NamedTemporaryFile(prefix='CliMAS-Report-', suffix='.pdf', delete=True) as tf:
tfpath = os.path.abspath(tf.name)
doc = pypandoc.convert(da.result(), 'latex', format='markdown', extra_args=(
'-o', tfpath,
'--latex-engine=/usr/local/texlive/2014/bin/x86_64-linux/pdflatex',
'--template=' + self.request.registry.settings['climas.doc_template_path'] + '/default.latex'
))
response = FileResponse(tfpath)
# response.content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
# response.content_disposition = "attachment; filename=CliMAS-Report.docx"
response.content_type = "application/pdf"
response.content_disposition = "attachment; filename=CliMAS-Report.pdf"
return response
示例3: export_to_ecard_view
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import content_type [as 别名]
def export_to_ecard_view(request):
import os, glob
from pkg_resources import resource_filename
from zipfile import ZipFile
from tempfile import NamedTemporaryFile
from pyramid.response import FileResponse
with NamedTemporaryFile(delete=True) as f:
os.chdir(resource_filename('tp_enroll', 'static/pictures'))
with ZipFile(f.name, 'w') as z:
for i in glob.glob('*'):
z.write(i)
f.flush()
f.seek(0)
response = FileResponse(f.name)
response.content_type = 'application/octet-stream'
response.content_disposition = 'attachment; filename="ecard.zip"'
return response