docs: document how to access component instance from within View (#1115)

This commit is contained in:
Juro Oravec 2025-04-10 09:39:52 +02:00 committed by GitHub
parent 5b01d6c3c6
commit d37291a3b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View file

@ -33,6 +33,18 @@ class ComponentView(ComponentExtension.ExtensionClass, View): # type: ignore
# NOTE: This attribute must be declared on the class for `View.as_view()` to allow
# us to pass `component` kwarg.
component = cast("Component", None)
"""
The component instance.
This is a dummy instance created solely for the View methods.
It is the same as if you instantiated the component class directly:
```py
component = Calendar()
component.render_to_response(request=request)
```
"""
def __init__(self, component: "Component", **kwargs: Any) -> None:
ComponentExtension.ExtensionClass.__init__(self, component)