A magical full-stack framework for Django.
Project description
Unicorn
The magical reactive component framework for Django ✨
Unicorn adds modern reactive component functionality to your Django templates without having to learn a new templating language or fight with complicated JavaScript frameworks. It seamlessly extends Django past its server-side framework roots without giving up all of its niceties or forcing you to rebuild your application. With Django Unicorn, you can quickly and easily add rich front-end interactions to your templates, all while using the power of Django.
https://www.django-unicorn.com has extensive documentation, code examples, and more!
⚡ Getting started
1. Install the package
Use your favorite package manager to install Unicorn:
uv add django-unicornpip install django-unicornpoetry add django-unicorn
2. Add django_unicorn to INSTALLED_APPS
# settings.py
INSTALLED_APPS = (
# other apps
"django_unicorn",
)
3. Update urls.py
# urls.py
import django_unicorn
urlpatterns = (
# other urls
path("unicorn/", include("django_unicorn.urls")),
)
4. Add Unicorn to the HTML template
<!-- template.html -->
{% load unicorn %}
<html>
<head>
{% unicorn_scripts %}
</head>
<body>
{% csrf_token %}
</body>
</html>
5. Create a component
python manage.py startunicorn myapp COMPONENT_NAME
Unicorn uses the term "component" to refer to a set of interactive functionality that can be put into templates. A component consists of a Django HTML template and a Python view class which contains the backend code. After running the management command, two new files will be created:
myapp/templates/unicorn/COMPONENT_NAME.html(component template)myapp/components/COMPONENT_NAME.py(component view)
6. Add the component to your template
<!-- template.html -->
{% load unicorn %}
<html>
<head>
{% unicorn_scripts %}
</head>
<body>
{% csrf_token %}
{% unicorn 'COMPONENT_NAME' %}
</body>
</html>
Example todo component
The unicorn: attributes bind the element to data and can also trigger methods by listening for events, e.g. click, input, keydown, etc.
<!-- todo.html -->
<div>
<form unicorn:submit.prevent="add">
<input type="text"
unicorn:model.defer="task"
unicorn:keyup.escape="task=''"
placeholder="New task" id="task"></input>
</form>
<button unicorn:click="add">Add</button>
<button unicorn:click="$reset">Clear all tasks</button>
<p>
{% if tasks %}
<ul>
{% for task in tasks %}
<li>{{ task }}</li>
{% endfor %}
</ul>
{% else %}
No tasks 🎉
{% endif %}
</p>
</div>
# todo.py
from django_unicorn.components import UnicornView
from django import forms
class TodoForm(forms.Form):
task = forms.CharField(min_length=2, max_length=20, required=True)
class TodoView(UnicornView):
form_class = TodoForm
task = ""
tasks = []
def add(self):
if self.is_valid():
self.tasks.append(self.task)
self.task = ""
✨ Wait, is this magic?
Sort of! At least it might feel like it. 🤩
Unicornprogressively enhances a normal Django view, so the initial render is fast and great for SEO.Unicornbinds to the elements you specify and automatically makes AJAX calls when needed.Unicornseamlessly updates the DOM when the HTML changes.
Focus on building regular Django templates and Python classes without needing to switch to another language or use unnecessary infrastructure.
🤯 But wait, there's more!
As if that wasn't enough, other features include:
- Form Validation
- Redirection
- Loading States
- Dirty States
- Partial Updates
- Polling
- Scroll Triggering
- Messages
- Javascript Integration
📖 Dig In
❤️ Support
This project is supported by GitHub Sponsors and Digital Ocean.
🔧 Contributors
Check out this guide for more details on how to contribute.
Thanks to the following wonderful people (emoji key) who have helped build Unicorn.
This project follows the all-contributors specification. Contributions of any kind welcome!
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_unicorn-0.65.2.tar.gz.
File metadata
- Download URL: django_unicorn-0.65.2.tar.gz
- Upload date:
- Size: 463.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
315428139fa1df2dd2a27ca560fbf1603de6aa0359772607c3ab067c9d2f3ed7
|
|
| MD5 |
f9b7943ccd3840bb21bf7ebf26f405fa
|
|
| BLAKE2b-256 |
bc64f3f2d9502d5739c4bede9e744dc8f15d32c8c21de836cee54ba035636665
|
Provenance
The following attestation bundles were made for django_unicorn-0.65.2.tar.gz:
Publisher:
publish.yml on django-commons/django-unicorn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_unicorn-0.65.2.tar.gz -
Subject digest:
315428139fa1df2dd2a27ca560fbf1603de6aa0359772607c3ab067c9d2f3ed7 - Sigstore transparency entry: 950852390
- Sigstore integration time:
-
Permalink:
django-commons/django-unicorn@ae9e1dc92f1ea3eb367a09ec21d7dbbd4c9ab578 -
Branch / Tag:
refs/tags/0.65.2 - Owner: https://github.com/django-commons
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae9e1dc92f1ea3eb367a09ec21d7dbbd4c9ab578 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_unicorn-0.65.2-py3-none-any.whl.
File metadata
- Download URL: django_unicorn-0.65.2-py3-none-any.whl
- Upload date:
- Size: 101.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8be9de5e4106cff388a7d4bcc40e5bdc1dc42bcdbe38af3e8a962c12fdacea82
|
|
| MD5 |
10cc873f7b21ec5dc69f6ac4c57dc076
|
|
| BLAKE2b-256 |
0d0b2b8e01acb55083c1c0e63899d9535be401e47c95f0a3712ae65c6f316da3
|
Provenance
The following attestation bundles were made for django_unicorn-0.65.2-py3-none-any.whl:
Publisher:
publish.yml on django-commons/django-unicorn
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_unicorn-0.65.2-py3-none-any.whl -
Subject digest:
8be9de5e4106cff388a7d4bcc40e5bdc1dc42bcdbe38af3e8a962c12fdacea82 - Sigstore transparency entry: 950852450
- Sigstore integration time:
-
Permalink:
django-commons/django-unicorn@ae9e1dc92f1ea3eb367a09ec21d7dbbd4c9ab578 -
Branch / Tag:
refs/tags/0.65.2 - Owner: https://github.com/django-commons
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ae9e1dc92f1ea3eb367a09ec21d7dbbd4c9ab578 -
Trigger Event:
push
-
Statement type: