quart.views module¶
-
class
quart.views.
MethodView
¶ Bases:
quart.views.View
A HTTP Method (verb) specific view class.
This has an implementation of
dispathc_request()
such that it calls a method based on the verb i.e. GET requests are handled by a get method. For example,class SimpleView(MethodView): async def get(id): return f"Get {id}" async def post(id): return f"Post {id}" app.add_url_rule('/<id>', view_func=SimpleView.as_view('simple'))
-
async
dispatch_request
(*args: Any, **kwargs: Any) → Union[Response, str, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None], Tuple[Union[Response, str, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], dict], Tuple[Union[Response, str, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], int], Tuple[Union[Response, str, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], int, dict]]¶ Override and return a Response.
This will be called with the request view_args, i.e. any url parameters.
-
async
-
class
quart.views.
MethodViewType
(name, bases, attributes)¶ Bases:
type
-
class
quart.views.
View
¶ Bases:
object
Use to define routes within a class structure.
A View subclass must implement the
dispatch_request()
in order to respond to requets. For automatic method finding based on the request HTTP Verb seeMethodView
.An example usage is,
class SimpleView: methods = ['GET'] async def dispatch_request(id): return f"ID is {id}" app.add_url_rule('/<id>', view_func=SimpleView.as_view('simple'))
Note that class
-
decorators
¶ A list of decorators to apply to a view method. The decorators are applied in the order of the list.
-
methods
¶ List of methods this view allows.
-
provide_automatic_options
¶ Override automatic OPTIONS if set, to either True or False.
-
classmethod
as_view
(name: str, *class_args: Any, **class_kwargs: Any) → Callable¶
-
decorators
: List[Callable] = []
-
async
dispatch_request
(*args: Any, **kwargs: Any) → Union[Response, str, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None], Tuple[Union[Response, str, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], dict], Tuple[Union[Response, str, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], int], Tuple[Union[Response, str, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], int, dict]]¶ Override and return a Response.
This will be called with the request view_args, i.e. any url parameters.
-
methods
: Optional[List[str]] = None
-
provide_automatic_options
: Optional[bool] = None
-