You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| view | `Callable | View` | The view function or class to convert. | N/A |
34
-
| compatibility | `bool` | If True, the component will be rendered in an iframe. When using compatibility mode `tranforms`, `strict_parsing`, and `request` arguments will be ignored. | `False` |
35
-
| transforms | `Iterable[Callable[[VdomDict], Any]]` | A list of functions that transforms the newly generated VDOM. The functions will be called on each VDOM node. | `tuple` |
34
+
| compatibility | `bool` | If True, the component will be rendered in an iframe. When using compatibility mode `tranforms`, `strict_parsing`, `request`, `args`, and `kwargs` arguments will be ignored. | `False` |
35
+
| transforms | `Sequence[Callable[[VdomDict], Any]]` | A list of functions that transforms the newly generated VDOM. The functions will be called on each VDOM node. | `tuple` |
36
36
| strict_parsing | `bool` | If True, an exception will be generated if the HTML does not perfectly adhere to HTML5. | `True` |
37
-
| request | `HttpRequest | None` | Request object to provide to the view. | `None` |
38
-
| args | `Iterable` | The positional arguments to pass to the view. | `tuple` |
39
-
| kwargs | `Dict | None` | The keyword arguments to pass to the view. | `None` |
40
37
41
38
<font size="4">**Returns**</font>
42
39
43
40
| Type | Description |
44
41
| --- | --- |
45
-
| `Component` | An IDOM component. |
46
-
| `None` | No component render. |
42
+
| `_ViewComponentConstructor` | A function that takes `request: HttpRequest | None, *args: Any, **kwargs: Any` and returns an IDOM component. |
43
+
44
+
??? warning "Existing limitations"
45
+
46
+
There are currently several limitations of using `view_to_component` that may be resolved in a future version of `django_idom`.
47
+
48
+
- Requires manual intervention to change request methods beyond `GET`.
49
+
- Does not currently load any HTML contained with a `<head>` tag
50
+
- Has no option to automatically intercept local anchor link (ex. `#!html <a href='example/'></a>`) click events
51
+
52
+
_Please note these limitations do not exist when using `compatibility` mode._
47
53
48
54
??? question "How do I use this for Class Based Views?"
49
55
50
-
You can simply pass your Class Based View directly into this function.
56
+
You can simply pass your Class Based View directly into `view_to_component`.
51
57
52
58
=== "components.py"
53
59
54
60
```python linenums="1"
55
61
from idom import component, html
62
+
from django.http import HttpResponse
63
+
from django.views import View
56
64
from django_idom.components import view_to_component
57
-
from .views import HelloWorldView
65
+
66
+
@view_to_component
67
+
class HelloWorldView(View):
68
+
def get(self, request):
69
+
return HttpResponse("Hello World!")
58
70
59
71
@component
60
72
def my_component():
61
73
return html.div(
62
-
view_to_component(HelloWorldView),
74
+
HelloWorldView(),
63
75
)
64
76
```
65
77
66
-
=== "views.py"
78
+
??? question "How do I transform views from external libraries?"
For views that rely on HTTP responses other than `GET` (such as `PUT`, `POST`, `PATCH`, etc), you should consider using compatibility mode to render your view within an iframe.
99
154
100
-
Any view can be rendered within compatibility mode. However, the `transforms`, `strict_parsing`, and `request` arguments do not apply to compatibility mode.
155
+
Any view can be rendered within compatibility mode. However, the `transforms`, `strict_parsing`, `request`, `args`, and `kwargs` arguments do not apply to compatibility mode.
101
156
102
157
Please note that by default the iframe is unstyled, and thus won't look pretty until you add some CSS.
103
158
104
159
=== "components.py"
105
160
106
161
```python linenums="1"
107
162
from idom import component, html
163
+
from django.http import HttpResponse
108
164
from django_idom.components import view_to_component
Allows you to defer loading a CSS stylesheet until a component begins rendering. This stylesheet must be stored within [Django's static files](https://docs.djangoproject.com/en/dev/howto/static-files/).
0 commit comments