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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.698s · 66.5MB
glibcpy 3.10–3.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.
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.
fixInstall 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.
fixAdd '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.
fixAdd `{% 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.
fixDefine 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.