Utilities
Overview¶
Utility functions provide various miscellaneous functionality for advanced use cases.
Pitfall
Any utility functions not documented here are not considered part of the public API and may change without notice.
Register Iframe¶
This function is used register a Django view as a ReactPy iframe
.
It is mandatory to use this function alongside view_to_iframe
.
1 2 3 4 5 6 7 8 9 10 11 |
|
See Interface
Parameters
Name | Type | Description | Default |
---|---|---|---|
view | Callable | View | str | The view to register. Can be a function or class based view, or a dotted path to a view. | N/A |
Returns
None
Only use this within AppConfig.ready()
You should always call register_iframe
within a Django AppConfig.ready()
method. This ensures you will retain multiprocessing compatibility, such as with ASGI web server workers.
Register Component¶
This function is used register a root component with ReactPy.
Typically, this function is automatically called on all components contained within Django templates.
1 2 3 4 5 6 7 8 9 10 |
|
See Interface
Parameters
Name | Type | Description | Default |
---|---|---|---|
component | ComponentConstructor | str | The component to register. Can be a component function or dotted path to a component. | N/A |
Returns
None
Only use this within MyAppConfig.ready()
You should always call register_component
within a Django MyAppConfig.ready()
method. This ensures you will retain multiprocessing compatibility, such as with ASGI web server workers.
Do I need to use this?
You typically will not need to use this function.
For security reasons, ReactPy requires all root components to be registered. However, all components contained within Django templates are automatically registered.
This function is commonly needed when you have configured your host
to a dedicated Django rendering application that doesn't have templates.
Django Query Postprocessor¶
This is the default postprocessor for the use_query
hook.
Since ReactPy is rendered within an asyncio
loop, this postprocessor is exists to prevent Django's SynchronousOnlyException
by recursively prefetching fields within Django's ORM. Note that this effectively eliminates Django's lazy execution behavior.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 5 |
|
See Interface
Parameters
Name | Type | Description | Default |
---|---|---|---|
data | QuerySet | Model | The Model or QuerySet to recursively fetch fields from. | N/A |
many_to_many | bool | Whether or not to recursively fetch ManyToManyField relationships. | True |
many_to_one | bool | Whether or not to recursively fetch ForeignKey relationships. | True |
Returns
Type | Description |
---|---|
QuerySet | Model | The Model or QuerySet with all fields fetched. |