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¶
This function is used manually register a root component with ReactPy.
1 2 3 4 5 6 7 8 |
|
Only use this within AppConfig.ready()
You should always call register_component
within a Django AppConfig.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 does not allow non-registered components to be root components. However, all components contained within Django templates are automatically considered root components.
This is typically only needed when you have a dedicated Django application as a rendering server that doesn't have templates, such as when modifying the template tag host
argument. On this dedicated rendering server, you would need to manually register your components.