quart.views module

class quart.views.MethodView

Bases: quart.views.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) → Union[Response, AnyStr, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None], Tuple[Union[Response, AnyStr, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], Union[Headers, Dict[str, Union[str, List[str], Tuple[str, ]]], List[Tuple[str, Union[str, List[str], Tuple[str, ]]]]]], Tuple[Union[Response, AnyStr, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], int], Tuple[Union[Response, AnyStr, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], int, Union[Headers, Dict[str, Union[str, List[str], Tuple[str, ]]], List[Tuple[str, Union[str, List[str], Tuple[str, ]]]]]]]

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 see MethodView.

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, AnyStr, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None], Tuple[Union[Response, AnyStr, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], Union[Headers, Dict[str, Union[str, List[str], Tuple[str, ]]], List[Tuple[str, Union[str, List[str], Tuple[str, ]]]]]], Tuple[Union[Response, AnyStr, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], int], Tuple[Union[Response, AnyStr, Dict[str, Any], AsyncGenerator[bytes, None], Generator[bytes, None, None]], int, Union[Headers, Dict[str, Union[str, List[str], Tuple[str, ]]], List[Tuple[str, Union[str, List[str], Tuple[str, ]]]]]]]

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