本文整理汇总了Python中starlette.responses.RedirectResponse方法的典型用法代码示例。如果您正苦于以下问题:Python responses.RedirectResponse方法的具体用法?Python responses.RedirectResponse怎么用?Python responses.RedirectResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类starlette.responses
的用法示例。
在下文中一共展示了responses.RedirectResponse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from starlette import responses [as 别名]
# 或者: from starlette.responses import RedirectResponse [as 别名]
def get(self, request: Request) -> Response:
# validate state
state = request.query_params["state"]
_state = request.session.pop("state", "unknown")
if state != _state:
return PlainTextResponse("Invalid state", status_code=403)
# retrieve tokens
code = request.query_params["code"]
tokens = self.kc.callback(code)
# request.session["tokens"] = json.dumps(tokens)
# retrieve user info
access_token = tokens["access_token"]
user = self.kc.fetch_userinfo(access_token)
request.session["user"] = json.dumps(user)
return RedirectResponse(self.redirect_uri)
示例2: docs_redirect
# 需要导入模块: from starlette import responses [as 别名]
# 或者: from starlette.responses import RedirectResponse [as 别名]
def docs_redirect():
return RedirectResponse(f"{prefix}/docs")
示例3: _get_badge_url
# 需要导入模块: from starlette import responses [as 别名]
# 或者: from starlette.responses import RedirectResponse [as 别名]
def _get_badge_url(owner, repo, ext, style):
return responses.RedirectResponse(
url=f"https://img.shields.io/endpoint.{ext}?url=https://dashboard.mergify.io/badges/{owner}/{repo}&style={style}",
status_code=302,
)
示例4: badge
# 需要导入模块: from starlette import responses [as 别名]
# 或者: from starlette.responses import RedirectResponse [as 别名]
def badge(owner, repo):
return responses.RedirectResponse(
url=f"https://dashboard.mergify.io/badges/{owner}/{repo}"
)
示例5: index
# 需要导入模块: from starlette import responses [as 别名]
# 或者: from starlette.responses import RedirectResponse [as 别名]
def index(): # pragma: no cover
return responses.RedirectResponse(url="https://mergify.io/")
示例6: handle_exc
# 需要导入模块: from starlette import responses [as 别名]
# 或者: from starlette.responses import RedirectResponse [as 别名]
def handle_exc(request, exc):
print(request, exc)
return RedirectResponse(url='/redirect')
示例7: redirect_root_to_docs
# 需要导入模块: from starlette import responses [as 别名]
# 或者: from starlette.responses import RedirectResponse [as 别名]
def redirect_root_to_docs(fast_app: FastAPI, func_name: str, endpoint: str, method: str) -> None:
"""Adds api route to server that redirects user from root to docs with opened `endpoint` description."""
@fast_app.get('/', include_in_schema=False)
async def redirect_to_docs() -> RedirectResponse:
operation_id = generate_operation_id_for_path(name=func_name, path=endpoint, method=method)
response = RedirectResponse(url=f'/docs#/default/{operation_id}')
return response
示例8: response
# 需要导入模块: from starlette import responses [as 别名]
# 或者: from starlette.responses import RedirectResponse [as 别名]
def response(self) -> RedirectResponse:
return RedirectResponse(url=self._url, status_code=self.status_code)