本文整理汇总了Python中pyramid.response.Response.headers['Content-Type']方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers['Content-Type']方法的具体用法?Python Response.headers['Content-Type']怎么用?Python Response.headers['Content-Type']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.headers['Content-Type']方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _response
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['Content-Type'] [as 别名]
def _response(self, data):
if data is None:
raise HTTPNotFound()
else:
response = Response(data)
response.headers['Content-Type'] = 'image/png'
return response
示例2: portrait_image
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['Content-Type'] [as 别名]
def portrait_image(model, request):
"""XXX: needs polishing. Return configured default portrait if not set
on user.
"""
response = Response()
cfg = ugm_general(model)
response.body = model.attrs[cfg.attrs['users_portrait_attr']]
response.headers['Content-Type'] = 'image/jpeg'
response.headers['Cache-Control'] = 'max-age=0'
return response
示例3: download
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headers['Content-Type'] [as 别名]
def download(model, request):
check_submitter_access(model, request)
a_type = model.attrs['attachment_type']
payload = model.attrs['payload']
response = Response()
if a_type == 'text':
response.text = html_2_text(payload)
response.headers['Content-Type'] = 'text/plain'
response.headers['Content-Disposition'] = \
'attachment;filename={0}.txt'.format(model.name)
elif a_type == 'file':
payload = pickle.loads(payload)
file_data = payload['file']
file_data.seek(0)
response.body = file_data.read()
response.headers['Content-Type'] = payload['mimetype']
response.headers['Content-Disposition'] = \
'attachment;filename={0}'.format(
payload['filename'].encode('utf-8'))
elif a_type == 'image':
payload = pickle.loads(payload)
scale = request.params.get('scale')
filename = payload['filename']
if scale:
image_data = payload['scales'][scale]
filename = '{0}_{1}.{2}'.format(
filename[:filename.rfind('.')], scale,
filename[filename.rfind('.') + 1:])
else:
image_data = payload['image']
image_data.seek(0)
response.body = image_data.read()
response.headers['Content-Type'] = payload['mimetype']
response.headers['Content-Disposition'] = \
'attachment;filename={0}'.format(filename)
return response