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
Copy file name to clipboardExpand all lines: README.md
+18-3Lines changed: 18 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ You can also check out the official Inertia docs at https://inertiajs.com/.
52
52
Render Inertia responses is simple, you can either use the provided inertia render function or, for the most common use case, the inertia decorator. The render function accepts four arguments, the first is your request object. The second is the name of the component you want to render from within your pages directory (without extension). The third argument is a dict of `props` that should be provided to your components. The final argument is `view_data`, for any variables you want to provide to your template, but this is much less common.
53
53
54
54
```python
55
-
from inertia.httpimport render
55
+
from inertia import render
56
56
from .models import Event
57
57
58
58
defindex(request):
@@ -64,7 +64,7 @@ def index(request):
64
64
Or use the simpler decorator for the most common use cases
65
65
66
66
```python
67
-
from inertia.httpimport inertia
67
+
from inertia import inertia
68
68
from .models import Event
69
69
70
70
@inertia('Event/Index')
@@ -79,7 +79,7 @@ def index(request):
79
79
If you have data that you want to be provided as a prop to every component (a common use-case is information about the authenticated user) you can use the `share` method. A common place to put this would be in some custom middleware.
On the front end, Inertia supports the concept of "partial reloads" where only the props requested
100
+
are returned by the server. Sometimes, you may want to use this flow to avoid processing a particularly slow prop on the intial load. In this case, you can use `Lazy props`. Lazy props aren't evaluated unless they're specifically requested by name in a partial reload.
101
+
102
+
```python
103
+
from inertia import lazy, inertia
104
+
105
+
@inertia('ExampleComponent')
106
+
defexample(request):
107
+
return {
108
+
'name': lambda: 'Brandon', # this will be rendered on the first load as usual
109
+
'data': lazy(lambda: some_long_calculation()), # this will only be run when specifically requested by partial props and WILL NOT be included on the initial load
110
+
}
111
+
```
112
+
98
113
### Json Encoding
99
114
100
115
Inertia Django ships with a custom JsonEncoder at `inertia.utils.InertiaJsonEncoder` that extends Django's
0 commit comments