# quart.views module

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[collections.abc.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]

  decorators: ClassVar[list[Callable]] = []
  methods: ClassVar[Collection[str] | None] = None
  provide_automatic_options: ClassVar[bool | None] = None
  init_every_request: ClassVar[bool] = True
  async dispatch_request(**kwargs)

    Override and return a Response.

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

    Parameters:

      kwargs (Any)

    Return type:

      ResponseReturnValue

  classmethod as_view(name, *class_args, **class_kwargs)
    Parameters:

      - name (str)

      - class_args (Any)

      - class_kwargs (Any)

    Return type:

      RouteCallable

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)

    Override and return a Response.

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

    Parameters:

      kwargs (Any)

    Return type:

      ResponseReturnValue