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


Python response.FileResponse方法代码示例

本文整理汇总了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() 
开发者ID:daq-tools,项目名称:kotori,代码行数:11,代码来源:views.py

示例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() 
开发者ID:ip-tools,项目名称:patzilla,代码行数:9,代码来源:views.py

示例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 
开发者ID:mazvv,项目名称:travelcrm,代码行数:9,代码来源:uploads.py

示例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) 
开发者ID:muesli-hd,项目名称:muesli,代码行数:6,代码来源:views.py

示例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) 
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:44,代码来源:__init__.py

示例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 
开发者ID:GFDRR,项目名称:thinkhazard,代码行数:45,代码来源:pdf.py


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