Render the component and wrap the content in the response class.
The response class is taken from Component.response_class. Defaults to django.http.HttpResponse.
This is the interface for the django.views.View class which allows us to use components as Django views with component.as_view().
Inputs: - args - Positional args for the component. This is the same as calling the component as {% component "my_comp" arg1 arg2 ... %} - kwargs - Kwargs for the component. This is the same as calling the component as {% component "my_comp" key1=val1 key2=val2 ... %} - slots - Component slot fills. This is the same as pasing {% fill %} tags to the component. Accepts a dictionary of { slot_name: slot_content } where slot_content can be a string or render function. - escape_slots_content - Whether the content from slots should be escaped. - context - A context (dictionary or Django's Context) within which the component is rendered. The keys on the context can be accessed from within the template. - NOTE: In "isolated" mode, context is NOT accessible, and data MUST be passed via component's args and kwargs.
Any additional args and kwargs are passed to the response_class.
Retrieve a 'provided' field. The field MUST have been previously 'provided' by the component's ancestors using the {% provide %} template tag.
Source code in src/django_components/context.py
77 78 79
@@ -78,7 +78,7 @@
f" To fix this, make sure that at least one ancestor of component '{component_name}' has"f" the variable '{key}' in their 'provide' attribute.")
-
We use the Context object to pass down info on inside of which component we are currently rendering.
Source code in src/django_components/context.py
535455
@@ -118,7 +118,7 @@
# is the top-most or not. If it is, then "_parent_component_id" is Nonecontext[_PARENT_COMP_CONTEXT_KEY]=context.get(_CURRENT_COMP_CONTEXT_KEY,None)context[_CURRENT_COMP_CONTEXT_KEY]=component_id
-
'Provide' given data under given key. In other words, this data can be retrieved using self.inject(key) inside of get_context_data() method of components that are nested inside the {% provide %} tag.
Render the component and wrap the content in the response class.
The response class is taken from Component.response_class. Defaults to django.http.HttpResponse.
This is the interface for the django.views.View class which allows us to use components as Django views with component.as_view().
Inputs: - args - Positional args for the component. This is the same as calling the component as {% component "my_comp" arg1 arg2 ... %} - kwargs - Kwargs for the component. This is the same as calling the component as {% component "my_comp" key1=val1 key2=val2 ... %} - slots - Component slot fills. This is the same as pasing {% fill %} tags to the component. Accepts a dictionary of { slot_name: slot_content } where slot_content can be a string or render function. - escape_slots_content - Whether the content from slots should be escaped. - context - A context (dictionary or Django's Context) within which the component is rendered. The keys on the context can be accessed from within the template. - NOTE: In "isolated" mode, context is NOT accessible, and data MUST be passed via component's args and kwargs.
Any additional args and kwargs are passed to the response_class.
Retrieve a 'provided' field. The field MUST have been previously 'provided' by the component's ancestors using the {% provide %} template tag.
Source code in src/django_components/context.py
77 78 79
@@ -1256,7 +1256,7 @@
f" To fix this, make sure that at least one ancestor of component '{component_name}' has"f" the variable '{key}' in their 'provide' attribute.")
-
We use the Context object to pass down info on inside of which component we are currently rendering.
Source code in src/django_components/context.py
535455
@@ -1296,7 +1296,7 @@
# is the top-most or not. If it is, then "_parent_component_id" is Nonecontext[_PARENT_COMP_CONTEXT_KEY]=context.get(_CURRENT_COMP_CONTEXT_KEY,None)context[_CURRENT_COMP_CONTEXT_KEY]=component_id
-
'Provide' given data under given key. In other words, this data can be retrieved using self.inject(key) inside of get_context_data() method of components that are nested inside the {% provide %} tag.
Source code in src/django_components/context.py
108109110
@@ -1670,7 +1670,7 @@
# NOTE: When debugging tests during development, it may be easier to change# this to `print()`trace(logger,full_msg)
-
This snippet is taken directly from IncludeNode.render(). Unfortunately the render logic doesn't separate out template loading logic from rendering, so we have to copy the method.
SlotRef allows to treat a slot as a variable. The slot is rendered only once the instance is coerced to string.
This is used to access slots as variables inside the templates. When a SlotRef is rendered in the template with {{ my_lazy_slot }}, it will output the contents of the slot.
Prepare directories that may contain component files:
Searches for dirs set in STATICFILES_DIRS settings. If none set, defaults to searching for a "components" app. The dirs in STATICFILES_DIRS must be absolute paths.
Paths are accepted only if they resolve to a directory. E.g. /path/to/django_project/my_app/components/.
If STATICFILES_DIRS is not set or empty, then BASE_DIR is required.
Source code in src/django_components/template_loader.py
This snippet is taken directly from IncludeNode.render(). Unfortunately the render logic doesn't separate out template loading logic from rendering, so we have to copy the method.
SlotRef allows to treat a slot as a variable. The slot is rendered only once the instance is coerced to string.
This is used to access slots as variables inside the templates. When a SlotRef is rendered in the template with {{ my_lazy_slot }}, it will output the contents of the slot.
Prepare directories that may contain component files:
Searches for dirs set in STATICFILES_DIRS settings. If none set, defaults to searching for a "components" app. The dirs in STATICFILES_DIRS must be absolute paths.
Paths are accepted only if they resolve to a directory. E.g. /path/to/django_project/my_app/components/.
If STATICFILES_DIRS is not set or empty, then BASE_DIR is required.
Source code in src/django_components/template_loader.py