Utilities
Overview¶
Utility functions provide various miscellaneous functionality. These are typically not used, but are available for advanced use cases.
Django Query Postprocessor¶
This is the default postprocessor for the use_query
hook.
This postprocessor is designed to avoid Django's SynchronousOnlyException
by recursively fetching all fields within a Model
or QuerySet
to prevent lazy execution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
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. |
Register Component¶
The register_component
function is used manually register a root component with ReactPy.
You should always call register_component
within a Django AppConfig.ready()
method to retain compatibility with ASGI webserver workers.
1 2 3 4 5 6 7 8 |
|
Do I need to register my components?
You typically will not need to use this function.
For security reasons, ReactPy does not allow non-registered components to be root components. However, all components contained within Django templates are automatically considered root components.
You only need to use this function if your host application does not contain any HTML templates that reference your components.
A common scenario where this is needed is when you are modifying the template tag host = ...
argument in order to configure a dedicated Django application as a rendering server for ReactPy. On this dedicated rendering server, you would need to manually register your components.