mirror of
https://github.com/django-components/django-components.git
synced 2025-08-04 14:28:18 +00:00
docs: document how to access component instance from within View (#1115)
This commit is contained in:
parent
5b01d6c3c6
commit
d37291a3b6
2 changed files with 36 additions and 0 deletions
|
@ -81,6 +81,30 @@ class Calendar(Component):
|
|||
|
||||
This is deprecated from v0.137 onwards, and will be removed in v1.0.
|
||||
|
||||
### Acccessing component instance
|
||||
|
||||
You can access the component instance from within the View methods by using the [`View.component`](../../../reference/api#django_components.ComponentView.component) attribute:
|
||||
|
||||
```py
|
||||
class Calendar(Component):
|
||||
...
|
||||
|
||||
class View:
|
||||
def get(self, request):
|
||||
return self.component.render_to_response(request=request)
|
||||
```
|
||||
|
||||
!!! note
|
||||
|
||||
The [`View.component`](../../../reference/api#django_components.ComponentView.component) instance 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)
|
||||
```
|
||||
|
||||
## Register URLs manually
|
||||
|
||||
To register the component as a route / endpoint in Django, add an entry to your
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue