![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
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!
pip install django-unicorn
OR poetry add django-unicorn
django_unicorn
to INSTALLED_APPS
# settings.py
INSTALLED_APPS = (
# other apps
"django_unicorn",
)
# urls.py
import django_unicorn
urlpatterns = (
# other urls
path("unicorn/", include("django_unicorn.urls")),
)
Unicorn
to the HTML template<!-- template.html -->
{% load unicorn %}
<html>
<head>
{% unicorn_scripts %}
</head>
<body>
{% csrf_token %}
</body>
</html>
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)<!-- template.html -->
{% load unicorn %}
<html>
<head>
{% unicorn_scripts %}
</head>
<body>
{% csrf_token %}
{% unicorn 'COMPONENT_NAME' %}
</body>
</html>
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 = ""
Sort of! At least it might feel like it. 🤩
Unicorn
progressively enhances a normal Django view, so the initial render is fast and great for SEO.Unicorn
binds to the elements you specify and automatically makes AJAX calls when needed.Unicorn
seamlessly 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.
As if that wasn't enough, other features include:
This project is supported by GitHub Sponsors and Digital Ocean.
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!
FAQs
A magical full-stack framework for Django.
We found that django-unicorn demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.