Getting Started
Get djust up and running in your Django project in minutes.
Installation
Requirements
- Python 3.9+
- Django 4.0+
- Redis (optional, for production caching)
Install via pip
pipinstalldjust
Add to Django settings
# settings.py
INSTALLED_APPS = [
...
'djust',
]
# Optional: Configure djust
LIVEVIEW_CONFIG = {
'use_websocket': True,
'css_framework': 'bootstrap5', # or 'tailwind'
}
Configure URL routing
# urls.py
fromdjango.urlsimport path, include
urlpatterns = [
...
path('', include('djust.urls')),
]
Set up WebSocket (for real-time updates)
# asgi.py
fromchannels.routingimport ProtocolTypeRouter, URLRouter
fromdjust.websocketimport LiveViewConsumer
application = ProtocolTypeRouter({
"websocket": URLRouter([
path("ws/liveview/", LiveViewConsumer.as_asgi()),
]),
})
Your First LiveView
1. Create a view
views.py
1# views.py
2fromdjustimport LiveView, event
3
4classCounterView(LiveView):
5 template_name = 'counter.html'
6
7 defmount(self, request, **kwargs):
8 self.count = 0
9
10 @event
11 defincrement(self):
12 self.count += 1
13
14 @event
15 defdecrement(self):
16 self.count -= 1
2. Create a template
templates/counter.html
1<!-- templates/counter.html -->
2<div dj-liveview>
3 <h1>Count: {{ count }}</h1>
4 <button dj-click="decrement" class="btn btn-secondary">
5 -
6 </button>
7 <button dj-click="increment" class="btn btn-primary">
8 +
9 </button>
10</div>
3. Add URL route
urls.py
1# urls.py
2fromdjango.urlsimport path
3from.viewsimport CounterView
4
5urlpatterns = [
6 path('counter/', CounterView.as_view(), name='counter'),
7]
4. Run and test
python manage.py runserverVisit http://localhost:8000/counter/ and click the buttons to see real-time updates!
Next Steps
- Core Concepts - Learn about LiveView architecture
- Components - Explore the component library
- Forms - Build forms with real-time validation