本文整理匯總了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)