quart.views module#
- class quart.views.MethodView#
Bases:
View
A HTTP Method (verb) specific view class.
This has an implementation of
dispatch_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) ResponseReturnValue #
Override and return a Response.
This will be called with the request view_args, i.e. any url parameters.
- 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 requests. 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.
- Type:
List[Callable]
- methods#
List of methods this view allows.
- Type:
Optional[List[str]]
- provide_automatic_options#
Override automatic OPTIONS if set, to either True or False.
- Type:
Optional[bool]
- classmethod as_view(name: str, *class_args: Any, **class_kwargs: Any) Callable #
- decorators: List[Callable] = []#
- async dispatch_request(*args: Any, **kwargs: Any) ResponseReturnValue #
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#