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]` = null |
| provide_automatic_options | `t.ClassVar[bool | None]` = null |
| 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 | Create a new instance of this view class for every request by default. If a view subclass sets this to False, the same instance is used for every request. |
Constructor
Signature
def View() - > null
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 | A valid Flask response object, string, tuple, or other supported return type for a route handler |
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.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The internal name of the view, used for URL building and endpoint identification |
| *class_args | t.Any | Positional arguments to be passed to the view class constructor when it is instantiated |
| **class_kwargs | t.Any | Keyword arguments to be passed to the view class constructor when it is instantiated |
Returns
| Type | Description |
|---|---|
ft.RouteCallable | A callable function that handles incoming requests by instantiating the class and calling its dispatch_request method |