High-flying components for perfectionists with deadlines
Project description
django-bird
High-flying components for perfectionists with deadlines.
[!CAUTION] This is an experimental, alpha attempt at a different approach to defining components in Django templates. It is not suitable for production use yet.
Requirements
- Python 3.10, 3.11, 3.12, 3.13
- Django 4.2, 5.0, 5.1
Installation
-
Install the package from PyPI:
python -m pip install django-bird # or if you like the new hotness uv add django-bird uv sync
-
Add the app to your Django project's
INSTALLED_APPS
:INSTALLED_APPS = [ ..., "django_bird", ..., ]
-
django-bird will automatically configure the necessary settings in your project.
If you need to customize the configuration or prefer to set up django-bird manually, you can set
DJANGO_BIRD["ENABLE_AUTO_CONFIG"] = False
in your settings.For detailed instructions, please refer to the Manual Setup section within the Configuration documentation.
Getting Started
django-bird is a library for creating reusable components in Django. Let's create a simple button component to show the basics of how to use the library.
Create a new directory named bird
in your project's main templates directory. This will be the primary location for your components.
templates/
└── bird/
Inside the bird directory, create a new file named button.html
. The filename determines the component's name.
templates/
└── bird/
└── button.html
In button.html
, create a simple HTML button. Use {{ slot }}
to indicate where the main content will go.
{# templates/bird/button.html #}
<button>
{{ slot }}
</button>
To use your component in a Django template, use the {% bird %}
templatetag. The content between {% bird %}
and {% endbird %}
becomes the {{ slot }}
content.
{% bird button %}
Click me!
{% endbird %}
django-bird automatically recognizes components in the bird directory, so no manual registration is needed. When Django processes the template, django-bird replaces the {% bird %}
tag with the component's HTML, inserting the provided content into the slot, resulting in:
<button>
Click me!
</button>
You now have a button component that can be easily reused across your Django project.
Documentation
django-bird offers features for creating flexible components, such as:
- Passing attributes to components
- Named slots for organizing content within components
- Subcomponents for building complex component structures
For a full overview of the features and configuration options, please refer to the documentation.
Motivation
Several excellent libraries for creating components in Django exist:
[!NOTE] Also worth mentioning is django-template-partials from Carlton Gibson. While not a full component library, it allows defining reusable chunks in a Django template, providing a lightweight approach to reusability.
These libraries are excellent in their own right, each solving specific problems in innovative ways: django-components is full-featured and will take most people far with custom components, django-unicorn offers a novel approach to adding interactivity without a full JavaScript framework, and django-cotton has a new way of defining custom components that has me very excited.
So, why another Django component library?
Most of the ones above focus on defining components on the Python side, which works for many use cases. For those focusing on the HTML and Django template side, they have made significant strides in improving the developer experience. However, as a developer with strong opinions (sometimes loosely held 😄) about API design, I wanted a different approach.
After watching Caleb Porzio's 2024 Laracon US talk introducing Flux, I could not shake the desire to bring something similar to Django. While there are plenty of libraries such as Shoelace or UI kits designed for use in any web application, and tools like SaaS Pegasus for whole Django project generation, I couldn't find a well-polished component library solely dedicated to Django templates with the level of polish that Flux has for Laravel.
Initially, I considered contributing to existing libraries or wrapping one to add the functionality I wanted. However, I decided to create a new library for several reasons:
- I wanted to respect the hard work of existing maintainers and avoid burdening them with features that may not align with their project's goals.
- While wrapping an existing library might have been technically feasible and okay license-wise, it didn't feel right to build an entire component system on top of someone else's work, especially for a project I might want to develop independently in the future.
- Building something new gives me the freedom to fully control the direction and architecture, without being constrained by design choices made in other libraries.
- Healthy competition among libraries helps drive innovation, and I see this as an opportunity to contribute to the broader Django ecosystem.
- Recent libraries like django-cotton and dj-angles are pushing Django templates in new and exciting directions and I wanted to join in on the fun. 😄
It's very early days for django-bird. What you see here is laying the foundation for a template-centric approach to Django components. The current implementation focuses on core functionality, setting the stage for future features and enhancements.
See the ROADMAP for planned features and the future direction of django-bird.
License
django-bird
is licensed under the MIT license. See the LICENSE
file for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_bird-0.1.0.tar.gz
.
File metadata
- Download URL: django_bird-0.1.0.tar.gz
- Upload date:
- Size: 100.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9950210c4c28da057b150e9222fe2c90177bcc038f68c1b49b36949f6ed3ffa5 |
|
MD5 | 72485bac5ff6959a4512d0d8baca5c8c |
|
BLAKE2b-256 | fc40b6a7475f53fcb7e511994b1376be4fb7b16245a65b3659d769b2d316517c |
File details
Details for the file django_bird-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: django_bird-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 881b9a223c9a3f64558e896d01b8efc662aea1d88841e664873fdb3e2d9a0712 |
|
MD5 | bb51e21ca94a9224fa8995a00be56fa7 |
|
BLAKE2b-256 | 6424c33bf76575da08e97b234bf761e0dc43e39557a674290b33edc080e9a52f |