本文整理汇总了Python中pyramid.response.FileResponse方法的典型用法代码示例。如果您正苦于以下问题:Python response.FileResponse方法的具体用法?Python response.FileResponse怎么用?Python response.FileResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response
的用法示例。
在下文中一共展示了response.FileResponse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: favicon_view
# 需要导入模块: from pyramid import response [as 别名]
# 或者: from pyramid.response import FileResponse [as 别名]
def favicon_view(request):
"""
http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/assets.html#registering-a-view-callable-to-serve-a-static-asset
"""
icon = resource_filename('kotori.frontend', 'static/favicon.ico')
if os.path.isfile(icon):
return FileResponse(icon, request=request)
else:
return HTTPNotFound()
示例2: favicon_view
# 需要导入模块: from pyramid import response [as 别名]
# 或者: from pyramid.response import FileResponse [as 别名]
def favicon_view(request):
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/assets.html#registering-a-view-callable-to-serve-a-static-asset
icon = resource_filename('patzilla.navigator', 'static/favicon.ico')
if os.path.isfile(icon):
return FileResponse(icon, request=request)
else:
return HTTPNotFound()
示例3: download
# 需要导入模块: from pyramid import response [as 别名]
# 或者: from pyramid.response import FileResponse [as 别名]
def download(self):
upload = Upload.get(self.request.params.get('id'))
response = FileResponse(
self.request.storage.base_path + '/' + upload.path,
request=self.request,
)
return response
示例4: favicon_view
# 需要导入模块: from pyramid import response [as 别名]
# 或者: from pyramid.response import FileResponse [as 别名]
def favicon_view(request):
here = os.path.dirname(__file__)
icon = os.path.join(here, "static", "favicon.ico")
return FileResponse(icon, request=request)
示例5: add_spec_view
# 需要导入模块: from pyramid import response [as 别名]
# 或者: from pyramid.response import FileResponse [as 别名]
def add_spec_view(
config: Configurator,
filepath: str,
route: str = "/openapi.yaml",
route_name: str = "pyramid_openapi3.spec",
) -> None:
"""Serve and register OpenApi 3.0 specification file.
:param filepath: absolute/relative path to the specification file
:param route: URL path where to serve specification file
:param route_name: Route name under which specification file will be served
"""
def register() -> None:
if hupper.is_active(): # pragma: no cover
hupper.get_reloader().watch_files([filepath])
spec_dict = read_yaml_file(filepath)
validate_spec(spec_dict)
spec = create_spec(spec_dict)
def spec_view(request: Request) -> FileResponse:
return FileResponse(filepath, request=request, content_type="text/yaml")
config.add_route(route_name, route)
config.add_view(route_name=route_name, view=spec_view)
custom_formatters = config.registry.settings.get("pyramid_openapi3_formatters")
config.registry.settings["pyramid_openapi3"] = {
"filepath": filepath,
"spec_route_name": route_name,
"spec": spec,
"request_validator": RequestValidator(
spec, custom_formatters=custom_formatters
),
"response_validator": ResponseValidator(
spec, custom_formatters=custom_formatters
),
}
config.action(("pyramid_openapi3_spec",), register, order=PHASE0_CONFIG)
示例6: create_pdf_report
# 需要导入模块: from pyramid import response [as 别名]
# 或者: from pyramid.response import FileResponse [as 别名]
def create_pdf_report(request):
"""View to create an asynchronous print job.
"""
publication_date = request.publication_date
locale = request.locale_name
division_code = request.matchdict.get("divisioncode")
force = "force" in request.params
filename = "{:s}-{:s}.pdf".format(division_code, locale)
s3_path = "reports/{:%Y-%m-%d}/{}".format(publication_date, filename)
local_path = os.path.join(tempfile.gettempdir(), filename)
if force or not request.s3_helper.download_file(s3_path, local_path):
categories = (
request.dbsession.query(HazardCategory)
.options(joinedload(HazardCategory.hazardtype))
.join(HazardCategoryAdministrativeDivisionAssociation)
.join(AdministrativeDivision)
.join(HazardLevel)
.filter(AdministrativeDivision.code == division_code)
.order_by(HazardLevel.order)
)
query_args = {"_query": {"_LOCALE_": request.locale_name}}
pages = [
request.route_url("pdf_cover", divisioncode=division_code, **query_args),
request.route_url("pdf_about", **query_args),
]
for cat in categories:
pages.append(
request.route_url(
"report_print",
divisioncode=division_code,
hazardtype=cat.hazardtype.mnemonic,
**query_args,
)
)
run(create_and_upload_pdf(local_path, pages, s3_path, request.s3_helper))
response = FileResponse(local_path, request=request, content_type="application/pdf")
response.headers["Content-Disposition"] = (
'attachment; filename="ThinkHazard.pdf"'
)
return response