Package: django-unicorn
UnicornThe magical reactive component framework for Django ✨Unicornadds 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.comhas extensive documentation, code examples, and more!⚡ Getting started1.Install the packagepip install django-unicornORpoetry add django-unicorn2. Adddjango_unicorntoINSTALLED_APPS# settings.pyINSTALLED_APPS=(# other apps"django_unicorn",)3. Update urls.py# urls.pyimportdjango_unicornurlpatterns=(# other urlspath("unicorn/",include("django_unicorn.urls")),)4. AddUnicornto the HTML template<!-- template.html -->{% load unicorn %}<html><head>{% unicorn_scripts %}</head><body>{% csrf_token %}</body></html>5.Create a componentpython manage.py startunicorn myapp COMPONENT_NAMEUnicornuses 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 componentTheunicorn:attributes bind the element to data and can also trigger methods by listening for events, e.g.click,input,keydown, etc.<!-- todo.html --><div><formunicorn:submit.prevent="add"><inputtype="text"unicorn:model.defer="task"unicorn:keyup.escape="task=''"placeholder="New task"id="task"></input></form><buttonunicorn:click="add">Add</button><buttonunicorn: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.pyfromdjango_unicorn.componentsimportUnicornViewfromdjangoimportformsclassTodoForm(forms.Form):task=forms.CharField(min_length=2,max_length=20,required=True)classTodoView(UnicornView):task=""tasks=[]defadd(self):ifself.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 ValidationRedirectionLoading StatesDirty StatesPartial UpdatesPollingScroll TriggeringMessagesJavascript Integration📖 Dig InDocumentationExamplesScreencastsChangelog❤️ SupportThis project is supported by GitHubSponsorsandDigital Ocean.🔧 ContributorsCheck outthis guidefor more details on how to contribute.Thanks to the following wonderful people (emoji key) who have helped buildUnicorn.Adam Hill💻⚠️Andres Vargas💻Eddy Ernesto del Valle Pino💻Yaser Al-Najjar💻Stephan Traub⚠️Fredrik Borg💻⚠️mbacicc💻Ron📖Franziskhan💻Josh Higgins⚠️💻Amayas Messara💻Apoorva Pandey⚠️💻Christian González💻📖robwa💻⚠️Preston Badeer📖Sergei📖💻⚠️bazubii💻⚠️Dan Caron📖Shantanu💻regoawt💻⚠️Lasse H. Bomholt💻Martey Dodoo📖Pierre💻Roman Imankulov⚠️💻Lemi Boyce💻Jack Sundberg💻siliconcow💻⚠️This project follows theall-contributorsspecification. Contributions of any kind welcome!