v0.124 (2025-01-07)ยค
__
Featยค
-
Instead of inlining the JS and CSS under
Component.jsandComponent.css, you can move them to their own files, and link the JS/CSS files withComponent.js_fileandComponent.css_file.Even when you specify the JS/CSS with
Component.js_fileorComponent.css_file, then you can still access the content underComponent.jsorComponent.css- behind the scenes, the content of the JS/CSS files will be set toComponent.js/Component.cssupon first access.The same applies to
Component.template_file, which will populateComponent.templateupon first access.With this change, the role of
Component.js/cssand the JS/CSS inComponent.Mediahas changed:- The JS/CSS defined in
Component.js/cssorComponent.js/css_fileis the "main" JS/CSS - The JS/CSS defined in
Component.Media.js/cssare secondary or additional
See the updated "Getting Started" tutorial
- The JS/CSS defined in
Refactorยค
-
The canonical way to define a template file was changed from
template_nametotemplate_file, to align with the rest of the API.template_nameremains for backwards compatibility. When you get / settemplate_name, internally this is proxied totemplate_file. -
The undocumented
Component.component_idwas removed. Instead, useComponent.id. Changes:- While
component_idwas unique every time you instantiatedComponent, the newidis unique every time you render the component (e.g. withComponent.render()) - The new
idis available only during render, so e.g. from withinget_context_data()
- While
-
Component's HTML / CSS / JS are now resolved and loaded lazily. That is, if you specify
template_name/template_file,js_file,css_file, orMedia.js/css, the file paths will be resolved only once you:- Try to access component's HTML / CSS / JS, or
- Render the component.
Read more on Accessing component's HTML / JS / CSS.
-
Component inheritance:
- When you subclass a component, the JS and CSS defined on parent's
Mediaclass is now inherited by the child component. - You can disable or customize Media inheritance by setting
extendattribute on theComponent.Medianested class. This work similarly to Django'sMedia.extend. - When child component defines either
templateortemplate_file, both of parent'stemplateandtemplate_fileare ignored. The same applies tojs_fileandcss_file.
- When you subclass a component, the JS and CSS defined on parent's
-
Autodiscovery now ignores files and directories that start with an underscore (
_), except__init__.py -
The Signals emitted by or during the use of django-components are now documented, together the
template_renderedsignal.