Examples

Note that all examples are deliberately left unstyled to present the simplest implementation.

Click counter

Source

<!-- unicorn/templates/unicorn/clicks.html -->
<div>
    <button unicorn:click="subtract">-</button>
    <input type="text" unicorn:model="clicks" value="{{ count }}" readonly></input>
    <button unicorn:click="add">+</button>
</div>
# unicorn/components/clicks.py
from django_unicorn.components import UnicornView


class ClicksView(UnicornView):
    count = 0

    def add(self):
        self.count += 1

    def subtract(self):
        self.count -= 1