faust.web.views
¶
Class-based views.
- class faust.web.views.View(app: AppT, web: Web)[source]¶
Web view (HTTP endpoint).
- exception ServerError(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)¶
Internal Server Error (500).
- exception ValidationError(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)¶
Invalid input in POST data (400).
- exception ParseError(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)¶
Malformed request (400).
- exception NotAuthenticated(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)¶
Authentication credentials were not provided (401).
- exception PermissionDenied(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)¶
No permission to perform action (403).
- exception NotFound(detail: Optional[str] = None, *, code: Optional[int] = None, **extra_context: Any)¶
Resource not found (404).
- classmethod from_handler(fun: Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]) Type[View] [source]¶
Decorate
async def
handler function to create view.- Return type:
_GenericAlias
[View
]
- get_methods() Set [source]¶
Return the supported methods for this view
- Return type:
_SpecialGenericAlias
- async dispatch(request: Any) Any [source]¶
Dispatch the request and perform any callbacks/cleanup.
- Return type:
- async on_request_error(request: Request, exc: WebError) Response [source]¶
Call when a request raises an exception.
- Return type:
- path_for(view_name: str, **kwargs: Any) str [source]¶
Return the URL path for view by name.
Supports match keyword arguments.
- Return type:
- url_for(view_name: str, _base_url: Optional[Union[str, URL]] = None, **kwargs: Any) URL [source]¶
Return the canonical URL for view by name.
Supports match keyword arguments. Can take optional base name, which if not set will be the canonical URL of the app.
- Return type:
- async head(request: Request, **kwargs: Any) Any [source]¶
Override
head
to define the HTTP HEAD handler.
- async get(request: Request, **kwargs: Any) Any [source]¶
Override
get
to define the HTTP GET handler.
- async post(request: Request, **kwargs: Any) Any [source]¶
Override
post
to define the HTTP POST handler.
- async put(request: Request, **kwargs: Any) Any [source]¶
Override
put
to define the HTTP PUT handler.
- async patch(request: Request, **kwargs: Any) Any [source]¶
Override
patch
to define the HTTP PATCH handler.
- async delete(request: Request, **kwargs: Any) Any [source]¶
Override
delete
to define the HTTP DELETE handler.
- async options(request: Request, **kwargs: Any) Any [source]¶
Override
options
to define the HTTP OPTIONS handler.
- async search(request: Request, **kwargs: Any) Any [source]¶
Override
search
to define the HTTP SEARCH handler.
- text(value: str, *, content_type: Optional[str] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[MutableMapping] = None) Response [source]¶
Create text response, using “text/plain” content-type.
- Return type:
- html(value: str, *, content_type: Optional[str] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[MutableMapping] = None) Response [source]¶
Create HTML response from string,
text/html
content-type.- Return type:
- json(value: Any, *, content_type: Optional[str] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[MutableMapping] = None) Response [source]¶
Create new JSON response.
Accepts any JSON-serializable value and will automatically serialize it for you.
The content-type is set to “application/json”.
- Return type:
- bytes(value: bytes, *, content_type: Optional[str] = None, status: int = 200, reason: Optional[str] = None, headers: Optional[MutableMapping] = None) Response [source]¶
Create new
bytes
response - for binary data.- Return type:
- async read_request_content(request: Request) bytes [source]¶
Return the request body as bytes.
- Return type:
- bytes_to_response(s: bytes) Response [source]¶
Deserialize byte string back into a response object.
- Return type:
- response_to_bytes(response: Response) bytes [source]¶
Convert response to serializable byte string.
The result is a byte string that can be deserialized using
bytes_to_response()
.- Return type:
- route(pattern: str, handler: Callable) Any [source]¶
Create new route from pattern and handler.
- Return type:
- faust.web.views.gives_model(Model: Type[ModelT]) Callable[[Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]], Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]] [source]¶
Decorate view function to automatically decode POST data.
The POST data is decoded using the model you specify.
- Return type:
_CallableGenericAlias
[_UnionGenericAlias
[_CallableGenericAlias
[View
,Request
,_UnionGenericAlias
[_GenericAlias
[Any
,Any
,Response
],_GenericAlias
[Response
]]],_CallableGenericAlias
[View
,Request
,Any
,Any
,_UnionGenericAlias
[_GenericAlias
[Any
,Any
,Response
],_GenericAlias
[Response
]]]],_UnionGenericAlias
[_CallableGenericAlias
[View
,Request
,_UnionGenericAlias
[_GenericAlias
[Any
,Any
,Response
],_GenericAlias
[Response
]]],_CallableGenericAlias
[View
,Request
,Any
,Any
,_UnionGenericAlias
[_GenericAlias
[Any
,Any
,Response
],_GenericAlias
[Response
]]]]]
- faust.web.views.takes_model(Model: Type[ModelT]) Callable[[Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]], Union[Callable[[View, Request], Union[Coroutine[Any, Any, Response], Awaitable[Response]]], Callable[[View, Request, Any, Any], Union[Coroutine[Any, Any, Response], Awaitable[Response]]]]] [source]¶
Decorate view function to return model data.
- Return type:
_CallableGenericAlias
[_UnionGenericAlias
[_CallableGenericAlias
[View
,Request
,_UnionGenericAlias
[_GenericAlias
[Any
,Any
,Response
],_GenericAlias
[Response
]]],_CallableGenericAlias
[View
,Request
,Any
,Any
,_UnionGenericAlias
[_GenericAlias
[Any
,Any
,Response
],_GenericAlias
[Response
]]]],_UnionGenericAlias
[_CallableGenericAlias
[View
,Request
,_UnionGenericAlias
[_GenericAlias
[Any
,Any
,Response
],_GenericAlias
[Response
]]],_CallableGenericAlias
[View
,Request
,Any
,Any
,_UnionGenericAlias
[_GenericAlias
[Any
,Any
,Response
],_GenericAlias
[Response
]]]]]