redirect¶
- class litestar.response.redirect.ASGIRedirectResponse[源代码]¶
基类:
ASGIResponseA low-level ASGI redirect response class.
- __init__(path: str | bytes, media_type: str | None = None, status_code: RedirectStatusType | None = None, headers: dict[str, Any] | None = None, background: BackgroundTask | BackgroundTasks | None = None, body: bytes | str = b'', content_length: int | None = None, cookies: Iterable[Cookie] | None = None, encoding: str = 'utf-8', is_head_response: bool = False) None[源代码]¶
A low-level ASGI response class.
- 参数:
background¶ -- A background task or a list of background tasks to be executed after the response is sent.
body¶ -- encoded content to send in the response body.
content_length¶ -- The response content length.
cookies¶ -- The response cookies.
encoding¶ -- The response encoding.
headers¶ -- The response headers.
is_head_response¶ -- A boolean indicating if the response is a HEAD response.
media_type¶ -- The response media type.
status_code¶ -- The response status code.
- class litestar.response.redirect.Redirect[源代码]¶
-
A redirect response.
- __init__(path: str, *, background: BackgroundTask | BackgroundTasks | None = None, cookies: ResponseCookies | None = None, encoding: str = 'utf-8', headers: ResponseHeaders | None = None, media_type: str | MediaType | None = None, status_code: RedirectStatusType | None = None, type_encoders: TypeEncodersMap | None = None, query_params: Mapping[str, str | Sequence[str]] | MultiDict | None = None) None[源代码]¶
Initialize the response.
- 参数:
path¶ -- A path to redirect to.
background¶ -- A background task or tasks to be run after the response is sent.
cookies¶ -- A list of
Cookieinstances to be set under the responseSet-Cookieheader.encoding¶ -- The encoding to be used for the response headers.
headers¶ -- A string keyed dictionary of response headers. Header keys are insensitive.
media_type¶ -- A value for the response
Content-Typeheader.status_code¶ -- An HTTP status code. The status code should be one of 301, 302, 303, 307 or 308, otherwise an exception will be raised.
type_encoders¶ -- A mapping of types to callables that transform them into types supported for serialization.
query_params¶ -- A dictionary of values from which the request's query will be generated.
- 抛出:
ImproperlyConfiguredException -- Either if status code is not a redirect status code or media type is not supported.
- to_asgi_response(request: Request, *, background: BackgroundTask | BackgroundTasks | None = None, cookies: Iterable[Cookie] | None = None, headers: dict[str, str] | None = None, is_head_response: bool = False, media_type: MediaType | str | None = None, status_code: int | None = None, type_encoders: TypeEncodersMap | None = None) ASGIResponse[源代码]¶
Create an ASGIResponse from a Response instance.
- 参数:
background¶ -- Background task(s) to be executed after the response is sent.
cookies¶ -- A list of cookies to be set on the response.
headers¶ -- Additional headers to be merged with the response headers. Response headers take precedence.
is_head_response¶ -- Whether the response is a HEAD response.
media_type¶ -- Media type for the response. If
media_typeis already set on the response, this is ignored.status_code¶ -- Status code for the response. If
status_codeis already set on the response, this istype_encoders¶ -- A dictionary of type encoders to use for encoding the response content.
- 返回:
An ASGIResponse instance.