當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。