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(**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.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.

Type:

ClassVar[list[Callable]]

methods#

List of methods this view allows.

Type:

ClassVar[Collection[str] | None]

provide_automatic_options#

Override automatic OPTIONS if set, to either True or False.

Type:

ClassVar[bool | None]

init_every_request#

Create a new instance of this class for every request.

Type:

ClassVar[bool]

classmethod as_view(name: str, *class_args: Any, **class_kwargs: Any) RouteCallable#
decorators: ClassVar[list[Callable]] = []#
async dispatch_request(**kwargs: Any) ResponseReturnValue#

Override and return a Response.

This will be called with the request view_args, i.e. any url parameters.

init_every_request: ClassVar[bool] = True#
methods: ClassVar[Collection[str] | None] = None#
provide_automatic_options: ClassVar[bool | None] = None#