View
Subclass this class and override :meth:dispatch_request to create a generic class-based view. Call :meth:as_view to create a view function that creates an instance of the class with the given arguments and calls its dispatch_request method with any URL variables.
Attributes
| Attribute | Type | Description |
|---|---|---|
| methods | `t.ClassVar[t.Collection[str] | None]` = None |
| provide_automatic_options | `t.ClassVar[bool | None]` = None |
| decorators | t.ClassVar[list[t.Callable[..., t.Any]]] = [] | A list of decorators to apply, in order, to the generated view function; remember that @decorator syntax is applied bottom to top, so the first decorator in the list would be the bottom decorator. |
| init_every_request | t.ClassVar[bool] = True | Controls whether a new instance of this view class is created for every request by default; if a view subclass sets this to False, the same instance is used for every request. |
Methods
dispatch_request()
@classmethod
def dispatch_request() - > ft.ResponseReturnValue
The actual view function behavior. Subclasses must override this and return a valid response. Any variables from the URL rule are passed as keyword arguments.
Returns
| Type | Description |
|---|---|
ft.ResponseReturnValue |
as_view()
@classmethod
def as_view(
name: str,
class_args: t.Any,
class_kwargs: t.Any
) - > ft.RouteCallable
Convert the class into a view function that can be registered for a route. By default, the generated view will create a new instance of the view class for every request and call its :meth:dispatch_request method. If the view class sets :attr:init_every_request to False, the same instance will be used for every request. Except for name, all other arguments passed to this method are forwarded to the view class __init__ method.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The name of the view function to be created. |
| class_args | t.Any | Positional arguments to pass to the view class's constructor. |
| class_kwargs | t.Any | Keyword arguments to pass to the view class's constructor. |
Returns
| Type | Description |
|---|---|
ft.RouteCallable |