Registry / web-framework / laces
library0.1.2pypypi✓ verified 24d ago

Laces is a Python library that provides a simple way to create self-rendering UI components for Django applications. It combines Python objects (data) with their corresponding Django templates, allowing components to be easily rendered in any parent template using a custom template tag. This approach helps in avoiding redundant data structuring and is particularly useful for nested components. The current version is 0.1.2, and releases occur semi-regularly, often driven by feature additions or bug fixes, with some significant gaps between versions.

pip install laces
INSTALL
IMPORT
SIG · LACES
L
laces
web-frameworkpythonv0.1.2
Install
4.1s avg
Import
674ms
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.698s · 66.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.1s · import 0.650s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Component
from laces.components import Component
MediaContainer
from laces.components import MediaContainer
Useful for combining JavaScript and CSS assets from multiple components.

This quickstart demonstrates how to set up and render a basic Laces component within a Django project. It includes the necessary Django settings configuration, component definition, and template usage with the `{% component %}` tag.

import os import django from django.conf import settings from django.template.backends.django import DjangoTemplates from django.urls import path from django.http import HttpResponse from django.shortcuts import render # Minimal Django setup (for demonstration purposes) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings') settings.configure( INSTALLED_APPS=[ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'laces' # Crucial: add 'laces' to INSTALLED_APPS ], TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ], ROOT_URLCONF=__name__, DEBUG=True, SECRET_KEY=os.environ.get('DJANGO_SECRET_KEY', 'a-very-secret-key-for-dev'), STATIC_URL='/static/' ) django.setup() # 1. Define your component from laces.components import Component class GreetingComponent(Component): template_name = "components/greeting_component.html" def get_context_data(self, parent_context=None): # You can access parent_context if rendering within another component/template return {"name": self.name, "greeting_message": f"Hello, {self.name}!"} def __init__(self, name="World", **kwargs): super().__init__(**kwargs) self.name = name # 2. Create Django template files # Save this as 'templates/components/greeting_component.html' # <p>{{ greeting_message }}</p> # Save this as 'templates/home.html' # {% load laces %} # <!DOCTYPE html> # <html> # <head><title>Laces Quickstart</title></head> # <body> # <h1>Laces Example</h1> # {% component component_instance %} # {% component another_component_instance %} # </body> # </html> # 3. Create a Django view def home_view(request): component_1 = GreetingComponent(name="Alice") component_2 = GreetingComponent(name="Bob") return render(request, "home.html", { "component_instance": component_1, "another_component_instance": component_2 }) # 4. Define URLs urlpatterns = [ path('', home_view, name='home'), ] # To run this minimal example, you would typically save the templates # and then run the Django development server. # For an actual project: # 1. Ensure 'templates/components/greeting_component.html' exists with content: <p>{{ greeting_message }}</p> # 2. Ensure 'templates/home.html' exists with content as above. # 3. Add 'laces' to INSTALLED_APPS in your project's settings.py. # 4. Define your component in an app's components.py (e.g., myapp/components.py). # 5. Use the component in a view and pass it to your template.
Debug
Known issues
gotchaThe `laces` library (PyPI package `laces`) is listed with a 'Development Status :: 3 - Alpha' classifier on PyPI. While it is used internally by Wagtail, this status technically implies that the API might not be fully stable and could undergo breaking changes in minor releases.
fix
Refer to the GitHub changelog before upgrading to new minor versions for potential breaking changes. Test upgrades thoroughly.
affects: 0.1.x
gotchaYou must explicitly add `'laces'` to your `INSTALLED_APPS` setting in Django for the component template tag and other features to be discovered and registered.
fix
In your `settings.py`, add `INSTALLED_APPS = ['laces', ...]`.
affects: All versions
gotchaThe `{% component %}` template tag requires `{% load laces %}` at the top of any Django template where it is used.
fix
Add `{% load laces %}` at the beginning of your Django template files that render Laces components.
affects: All versions
deprecatedFor projects using Wagtail versions *prior* to 6.0, it is recommended to continue using Wagtail's native component imports (`wagtail.admin.ui.components` and `wagtail.admin.templatetags.wagtailadmin_tags`). While Laces components are now integrated into Wagtail 6.0+, using Laces directly in older Wagtail versions could lead to conflicts or unexpected behavior.
fix
If on Wagtail < 6.0, continue using `wagtail.admin.ui.components.Component` and `{% load wagtailadmin_tags %}`. If migrating to Wagtail 6.0+, you can safely switch to or use `laces` imports interchangeably.
affects: Wagtail < 6.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'laces'
The 'laces' Python package is not installed in your environment or Django cannot find it in its Python path.
fix
Install the library using pip: `pip install laces`
django.core.exceptions.ImproperlyConfigured: 'laces' is not in your INSTALLED_APPS setting.
You have likely installed the 'laces' package, but have not added it to the `INSTALLED_APPS` list in your Django project's settings.py file.
fix
Add 'laces' to your `INSTALLED_APPS` in `settings.py`: `INSTALLED_APPS = ['laces', ...]`
TemplateSyntaxError: 'component' is not a registered tag library
You are attempting to use the `{% component %}` template tag in a Django template without loading the 'laces' tag library first.
fix
Add `{% load laces %}` at the top of any Django template where you use the `{% component %}` tag.
AttributeError: 'MyComponent' object has no attribute 'template_name'
A custom component subclassing `laces.components.Component` is being rendered without defining the `template_name` attribute or overriding the `render_html` method, which are necessary for the component to know how to render itself.
fix
Define a `template_name` attribute on your component class: `class MyComponent(Component): template_name = 'my_app/components/my_component.html'` or override `render_html`.
Upgrade
Version history
0.1.2latest on PyPI · released Jan 14, 2025
Audit
Dependencies
DjangorequiredCore framework dependency for component rendering and integration.
Agent activity
9 hits · last 30 days
node
8
Resources
laces — pip install laces · libregistry