Module Contents#

django_unicorn.components.unicorn_view.convert_to_snake_case(s: str) str#
django_unicorn.components.unicorn_view.convert_to_dash_case(s: str) str#
django_unicorn.components.unicorn_view.convert_to_pascal_case(s: str) str#
django_unicorn.components.unicorn_view.get_locations(component_name: str) List[Tuple[str, str]]#
django_unicorn.components.unicorn_view.construct_component(component_class, component_id, component_name, component_key, parent, request, component_args, **kwargs)#

Constructs a class instance.

class django_unicorn.components.unicorn_view.UnicornView(component_args: Optional[List] = None, **kwargs)#

Bases: django.views.generic.base.TemplateView

Render a template. Pass keyword arguments from the URLconf to the context.

component_name: str = ''#
component_key: str = ''#
component_id: str = ''#
component_args: List#
component_kwargs: Dict#
call(function_name, *args)#

Add a JavaScript method name and arguments to be called after the component is rendered.


Hook that gets called when the component is first created.


Hook that gets called when the component’s data is hydrated.


Hook that gets called after all component methods are executed.


Hook that gets called after the component has been rendered.


Hook that gets called after the component’s parent has been rendered.

updating(name, value)#

Hook that gets called when a component’s data is about to get updated.

updated(name, value)#

Hook that gets called when a component’s data is updated.

calling(name, args)#

Hook that gets called when a component’s method is about to get called.

called(name, args)#

Hook that gets called when a component’s method is called.

render(*, init_js=False, extra_context=None, request=None) str#

Renders a UnicornView component with the public properties available. Delegates to a UnicornTemplateResponse to actually render a response.

  • init_js (param) – Whether or not to include the Javascript required to initialize the component.

  • extra_context (param) –

  • request (param) – Set the request for rendering. Usually it will be in the context, but it is missing when the component is re-rendered as a direct view, so it needs to be set explicitly.

dispatch(request, *args, **kwargs)#

Called by the as_view class method when utilizing a component directly as a view.

get_frontend_context_variables() str#

Get publicly available properties and output them in a string-encoded JSON object.


Overrides the standard get_context_data to add in publicly available properties and methods.

is_valid(model_names: Optional[List] = None) bool#
validate(model_names: Optional[List] = None) Dict#

Validates the data using the form_class set on the component.


model_names – Only include validation errors for specified fields. If none, validate everything.

static create(*, component_id: str, component_name: str, component_key: str = '', parent: UnicornView = None, request: django.http.HttpRequest = None, use_cache=True, component_args: Optional[List] = None, kwargs: Optional[Dict[str, Any]] = None) UnicornView#

Find and instantiate a component class based on component_name.

  • component_id (param) – Id of the component. Required.

  • component_name (param) – Name of the component. Used to locate the correct UnicornView component class and template if necessary. Required.

  • component_key (param) – Key of the component to allow multiple components of the same name to be differentiated. Optional.

  • parent (param) – The parent component of the current component.

  • component_args (param) – Arguments for the component passed in from the template. Defaults to [].

  • kwargs (param) – Keyword arguments for the component passed in from the template. Defaults to {}.


Instantiated UnicornView component. Raises ComponentModuleLoadError or ComponentClassLoadError if the component could not be loaded.

classmethod as_view(**initkwargs)#

Main entry point for a request-response process.