當前位置: 首頁>>代碼示例>>Python>>正文


Python responses.HTMLResponse方法代碼示例

本文整理匯總了Python中starlette.responses.HTMLResponse方法的典型用法代碼示例。如果您正苦於以下問題:Python responses.HTMLResponse方法的具體用法?Python responses.HTMLResponse怎麽用?Python responses.HTMLResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在starlette.responses的用法示例。


在下文中一共展示了responses.HTMLResponse方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: register_route

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def register_route(self, app):
        self.app = app
        from starlette.responses import JSONResponse, HTMLResponse

        self.app.add_route(
            self.config.spec_url,
            lambda request: JSONResponse(self.spectree.spec),
        )

        for ui in PAGES:
            self.app.add_route(
                f'/{self.config.PATH}/{ui}',
                lambda request, ui=ui: HTMLResponse(
                    PAGES[ui].format(self.config.spec_url)
                ),
            ) 
開發者ID:0b01001001,項目名稱:spectree,代碼行數:18,代碼來源:starlette_plugin.py

示例2: homepage

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def homepage(request):
    s = request.query_params.getlist("s")
    if s:
        s = s[0].strip()
        fixed, steps = fix_encoding_and_explain(s)
        return HTMLResponse(
            INDEX.format(
                output="<textarea>{}</textarea>".format(escape(fixed)),
                steps=escape(steps_to_python(s, steps)),
                s=escape(s),
                examples="\n".join(examples),
            )
        )
    else:
        return HTMLResponse(
            INDEX.format(output="", s="", steps="", examples="\n".join(examples),)
        ) 
開發者ID:simonw,項目名稱:ftfy-web,代碼行數:19,代碼來源:ftfy_app.py

示例3: get_redoc_html

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def get_redoc_html(
    *,
    openapi_url: str,
    title: str,
    redoc_js_url: str = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js",
    redoc_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
    with_google_fonts: bool = True,
) -> HTMLResponse:
    html = f"""
    <!DOCTYPE html>
    <html>
    <head>
    <title>{title}</title>
    <!-- needed for adaptive design -->
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    """
    if with_google_fonts:
        html += """
    <link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
    """
    html += f"""
    <link rel="shortcut icon" href="{redoc_favicon_url}">
    <!--
    ReDoc doesn't change outer page styles
    -->
    <style>
      body {{
        margin: 0;
        padding: 0;
      }}
    </style>
    </head>
    <body>
    <redoc spec-url="{openapi_url}"></redoc>
    <script src="{redoc_js_url}"> </script>
    </body>
    </html>
    """
    return HTMLResponse(html) 
開發者ID:tiangolo,項目名稱:fastapi,代碼行數:42,代碼來源:docs.py

示例4: render_playground

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def render_playground(  # pylint: disable=unused-argument
        self, request: Request
    ) -> Response:
        return HTMLResponse(PLAYGROUND_HTML) 
開發者ID:mirumee,項目名稱:ariadne,代碼行數:6,代碼來源:asgi.py

示例5: _starlette_handler

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def _starlette_handler(self):
        from starlette.responses import HTMLResponse, JSONResponse
        from starlette.staticfiles import StaticFiles

        async def swagger_doc_handler(request):
            return HTMLResponse(content=self.doc_html, media_type='text/html')

        async def swagger_editor_handler(request):
            return JSONResponse(content=self.editor_html, media_type='text/html')

        async def swagger_config_handler(request):
            host = '{}:{}'.format(request.url.hostname, request.url.port)
            return JSONResponse(self.get_config(host))

        self._app.router.add_route(self._uri(''), swagger_doc_handler, ['get'], 'swagger-ui')
        self._app.router.add_route(self._uri('/'), swagger_doc_handler, ['get'], 'swagger-ui')

        if self._editor:
            self._app.router.add_route(
                self._uri('/editor'), swagger_editor_handler, ['get'], 'swagger-editor')

        self._app.router.add_route(self._uri('/swagger.json'),
                                   swagger_config_handler, ['get'], 'swagger-config')
        self._app.router.mount(self._uri('/'),
                               app=StaticFiles(directory='{}/'.format(self.static_dir)),
                               name='swagger-static-files') 
開發者ID:PWZER,項目名稱:swagger-ui-py,代碼行數:28,代碼來源:core.py

示例6: index

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def index(request):
    html = path/'view'/'index.html'
    return HTMLResponse(html.open().read()) 
開發者ID:pankymathur,項目名稱:google-app-engine,代碼行數:5,代碼來源:server.py

示例7: get

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def get(self, request: Request) -> Response:
        config = get_graphql_config(request)
        graphql_endpoint = request["root_path"] + config.path
        subscriptions_endpoint = None
        if config.subscriptions:
            subscriptions_endpoint = request["root_path"] + config.subscriptions.path
        graphiql = config.graphiql
        assert graphiql is not None
        html = graphiql.render_template(
            graphql_endpoint=graphql_endpoint,
            subscriptions_endpoint=subscriptions_endpoint,
        )
        return HTMLResponse(html) 
開發者ID:tartiflette,項目名稱:tartiflette-asgi,代碼行數:15,代碼來源:_endpoints.py

示例8: get

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def get(self, request):
        html = get_playground_html(request.url.path, self.PLAYGROUND_SETTINGS)
        return HTMLResponse(html) 
開發者ID:ethe,項目名稱:pygraphy,代碼行數:5,代碼來源:view.py

示例9: setup

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def setup(self) -> None:
        if self.openapi_url:

            async def openapi(req: Request) -> JSONResponse:
                root_path = req.scope.get("root_path", "").rstrip("/")
                return JSONResponse(self.openapi(root_path))

            self.add_route(self.openapi_url, openapi, include_in_schema=False)
        if self.openapi_url and self.docs_url:

            async def swagger_ui_html(req: Request) -> HTMLResponse:
                root_path = req.scope.get("root_path", "").rstrip("/")
                openapi_url = root_path + self.openapi_url
                oauth2_redirect_url = self.swagger_ui_oauth2_redirect_url
                if oauth2_redirect_url:
                    oauth2_redirect_url = root_path + oauth2_redirect_url
                return get_swagger_ui_html(
                    openapi_url=openapi_url,
                    title=self.title + " - Swagger UI",
                    oauth2_redirect_url=oauth2_redirect_url,
                    init_oauth=self.swagger_ui_init_oauth,
                )

            self.add_route(self.docs_url, swagger_ui_html, include_in_schema=False)

            if self.swagger_ui_oauth2_redirect_url:

                async def swagger_ui_redirect(req: Request) -> HTMLResponse:
                    return get_swagger_ui_oauth2_redirect_html()

                self.add_route(
                    self.swagger_ui_oauth2_redirect_url,
                    swagger_ui_redirect,
                    include_in_schema=False,
                )
        if self.openapi_url and self.redoc_url:

            async def redoc_html(req: Request) -> HTMLResponse:
                root_path = req.scope.get("root_path", "").rstrip("/")
                openapi_url = root_path + self.openapi_url
                return get_redoc_html(
                    openapi_url=openapi_url, title=self.title + " - ReDoc"
                )

            self.add_route(self.redoc_url, redoc_html, include_in_schema=False)
        self.add_exception_handler(HTTPException, http_exception_handler)
        self.add_exception_handler(
            RequestValidationError, request_validation_exception_handler
        ) 
開發者ID:tiangolo,項目名稱:fastapi,代碼行數:51,代碼來源:applications.py

示例10: get_swagger_ui_html

# 需要導入模塊: from starlette import responses [as 別名]
# 或者: from starlette.responses import HTMLResponse [as 別名]
def get_swagger_ui_html(
    *,
    openapi_url: str,
    title: str,
    swagger_js_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui-bundle.js",
    swagger_css_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui.css",
    swagger_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
    oauth2_redirect_url: Optional[str] = None,
    init_oauth: Optional[dict] = None,
) -> HTMLResponse:

    html = f"""
    <!DOCTYPE html>
    <html>
    <head>
    <link type="text/css" rel="stylesheet" href="{swagger_css_url}">
    <link rel="shortcut icon" href="{swagger_favicon_url}">
    <title>{title}</title>
    </head>
    <body>
    <div id="swagger-ui">
    </div>
    <script src="{swagger_js_url}"></script>
    <!-- `SwaggerUIBundle` is now available on the page -->
    <script>
    const ui = SwaggerUIBundle({{
        url: '{openapi_url}',
    """

    if oauth2_redirect_url:
        html += f"oauth2RedirectUrl: window.location.origin + '{oauth2_redirect_url}',"

    html += """
        dom_id: '#swagger-ui',
        presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIBundle.SwaggerUIStandalonePreset
        ],
        layout: "BaseLayout",
        deepLinking: true,
        showExtensions: true,
        showCommonExtensions: true
    })"""

    if init_oauth:
        html += f"""
        ui.initOAuth({json.dumps(jsonable_encoder(init_oauth))})
        """

    html += """
    </script>
    </body>
    </html>
    """
    return HTMLResponse(html) 
開發者ID:tiangolo,項目名稱:fastapi,代碼行數:57,代碼來源:docs.py


注:本文中的starlette.responses.HTMLResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。