v0.147.0ยค
Added support for Django 6.0, CSS variables, and component tree navigation.
Breaking changes ๐จ๐ขยค
-
Dropped support for Python 3.8 and 3.9.
-
Dropped support for Django 5.1.
Featยค
-
CSS variables with
get_css_data()Pass data from Python to CSS with
get_css_data().get_css_data()returns a dictionary. This data is automatically converted to CSS custom properties and made available in your component's CSS.In your CSS file, access these variables using
var().CSS variables are automatically scoped to each component instance, allowing different instances of the same component to have different variable values.
Example:
class ThemeableButton(Component): template_file = "button.html" css_file = "button.css" class Kwargs: theme: str = "default" def get_css_data(self, args, kwargs: Kwargs, slots, context): themes = { "default": {"bg": "#f0f0f0", "color": "#333"}, "primary": {"bg": "#0275d8", "color": "#fff"}, "danger": {"bg": "#d9534f", "color": "#fff"}, } css_vars = themes.get(kwargs.theme, themes["default"]) return css_vars -
Component tree navigation:
parent,root, andancestorsproperties.Components can now access their parent component, root component, and all ancestors during rendering. These properties are part of the Render API and allow components to navigate the component tree.
Component.parent- Returns the parent component instance, orNoneif this is the root component.Component.root- Returns the root component instance (top-most ancestor), orselfif this is the root.Component.ancestors- Returns an iterator that yields all ancestor component instances, walking up the tree.
Example:
class Theme(Component): ... class Table(Component): def get_template_data(self, args, kwargs, slots, context): if self.parent is not None: # This component is nested in another component # Access parent's data if isinstance(self.parent, Theme): theme_color = self.parent.kwargs.get("color", "default") ...See #1252
-
New
on_extension_createdhook for extensions.New hook is called when the extension class is instantiated during Django startup.
Use this hook to perform initialization logic that needs to run at server startup.
Example:
Fixยค
-
Add missing export of
OnCssLoadedContextandOnJsLoadedContext -
Fixed bug where Python expressions in template tags were not evaluated correctly when the expression was on a separate line.
See #1255
-
Fixed bug where multiple attributes with the same name (e.g.,
class) were not being merged correctly in{% html_attrs %}.See #1281
Previously, when using duplicate
classorstyleattributes with both variables and literals, only the first value was used. Now all values are properly merged:Both
btn_classand the literal string are now merged together.