diff --git a/dev/concepts/fundamentals/render_api/index.html b/dev/concepts/fundamentals/render_api/index.html index be543e3f..f1077bb4 100644 --- a/dev/concepts/fundamentals/render_api/index.html +++ b/dev/concepts/fundamentals/render_api/index.html @@ -22,32 +22,38 @@ args=(123, "str"), slots={"footer": "MY_SLOT"}, ) -
If you try to access the Render API outside of a render call, you will get a RuntimeError
.
Component ID (or render ID) is a unique identifier for the current render call.
That means that if you call Component.render()
multiple times, the ID will be different for each call.
It is available as self.id
.
All the component inputs are captured and available as self.input
.
self.input
(ComponentInput
) has the mostly the same fields as the input to Component.render()
. This includes:
args
- List of positional argumentskwargs
- Dictionary of keyword argumentsslots
- Dictionary of slots. Values are normalized to Slot
instancescontext
- Context
object that should be used to render the componentComponent.render()
like type
and render_dependencies
Thus, use can use self.input.args
and self.input.kwargs
to access the positional and keyword arguments passed to Component.render()
.
class Table(Component):
- def get_context_data(self, *args, **kwargs):
- # Access component's inputs, slots and context
- assert self.input.args == [123, "str"]
- assert self.input.kwargs == {"variable": "test", "another": 1}
- footer_slot = self.input.slots["footer"]
- some_var = self.input.context["some_var"]
-
- return {}
-
-rendered = TestComponent.render(
- kwargs={"variable": "test", "another": 1},
- args=(123, "str"),
- slots={"footer": "MY_SLOT"},
-)
-
If the component was either:
request
kwargRenderContext
Then the request object will be available in self.request
.
If the request object is available, you will also be able to access the context processors
data in self.context_processors_data
.
This is a dictionary with the context processors data.
If the request object is not available, then self.context_processors_data
will be an empty dictionary.
Read more about the request object and context processors in the HTTP Request section.
from django.http import HttpRequest
-
-class Table(Component):
- def get_context_data(self, *args, **attrs):
- # Access the request object and Django's context processors
- assert self.request.GET == {"query": "something"}
- assert self.context_processors_data['user'].username == "admin"
+
If you try to access the Render API outside of a render call, you will get a RuntimeError
.
Component ID (or render ID) is a unique identifier for the current render call.
That means that if you call Component.render()
multiple times, the ID will be different for each call.
It is available as self.id
.
The ID is a 7-letter alphanumeric string in the format cXXXXXX
, where XXXXXX
is a random string of 6 alphanumeric characters (case-sensitive).
E.g. c1a2b3c
.
A single render ID has a chance of collision 1 in 57 billion. However, due to birthday paradox, the chance of collision increases to 1% when approaching ~33K render IDs.
Thus, there is currently a soft-cap of ~30K components rendered on a single page.
If you need to expand this limit, please open an issue on GitHub.
class Table(Component):
+ def get_context_data(self, *args, **attrs):
+ # Access component's ID
+ assert self.id == "djc1A2b3c"
+
+ return {}
+
All the component inputs are captured and available as self.input
.
self.input
(ComponentInput
) has the mostly the same fields as the input to Component.render()
. This includes:
args
- List of positional argumentskwargs
- Dictionary of keyword argumentsslots
- Dictionary of slots. Values are normalized to Slot
instancescontext
- Context
object that should be used to render the componentComponent.render()
like type
and render_dependencies
Thus, use can use self.input.args
and self.input.kwargs
to access the positional and keyword arguments passed to Component.render()
.
class Table(Component):
+ def get_context_data(self, *args, **kwargs):
+ # Access component's inputs, slots and context
+ assert self.input.args == [123, "str"]
+ assert self.input.kwargs == {"variable": "test", "another": 1}
+ footer_slot = self.input.slots["footer"]
+ some_var = self.input.context["some_var"]
return {}
-rendered = Table.render(
- request=HttpRequest(),
-)
-