Package: turbo-django
Unmaintained // Turbo for Django[!WARNING]This library is unmaintained. Integrating Hotwire and Django is so easy
that you are probably better served by writing a little bit of Python in your code
than using a full-blown library that adds another level of abstraction.
It also seems that the Django community is leaning more towards HTMX than Hotwire
so you might want to look over there if you want more "support"
(but we still think that Hotwire is very well suited to be used with Django)IntegrateHotwire Turbowith Django with ease.RequirementsPython 3.8+Django 3.1+Channels 3.0+(Optional for Turbo Frames, but needed for Turbo Stream support)InstallationTurbo Django is available on PyPI - to install it, just run:pip install turbo-djangoAddturboandchannelstoINSTALLED_APPS, and copy the followingCHANNEL_LAYERSsetting:INSTALLED_APPS=[...'turbo','channels'...]CHANNEL_LAYERS={"default":{# You will need to `pip install channels_redis` and configure a redis instance.# Using InMemoryChannelLayer will not work as the memory is not shared between threads.# See https://channels.readthedocs.io/en/latest/topics/channel_layers.html"BACKEND":"channels_redis.core.RedisChannelLayer","CONFIG":{"hosts":[("127.0.0.1",6379)],},}}And collect static files if the development server is not hosting them:./manage.pycollectstaticNote: Both Hotwire and this library are still in beta development and may introduce breaking API changes between releases.  It is advised to pin the library to a specific version during install.QuickstartWant to see Hotwire in action? Here's a simple broadcast that can be setup in less than a minute.The basics:A Turbo Stream class is declared in python.A template subscribes to the Turbo Stream.HTML is be pushed to all subscribed pages which replaces the content of specified HTML p tag.ExampleFirst, in a django app calledquickstart, declareBroadcastStreamin a file namedstreams.py.# streams.pyimportturboclassBroadcastStream(turbo.Stream):passThen, create a template that subscribes to the stream.fromdjango.urlsimportpathfromdjango.views.genericimportTemplateViewurlpatterns=[path('quickstart/',TemplateView.as_view(template_name='broadcast_example.html'))]# broadcast_example.html

{% load turbo_streams %}<!DOCTYPE html><htmllang="en"><head>{% include "turbo/head.html" %}</head><body>{% turbo_subscribe 'quickstart:BroadcastStream' %}<pid="broadcast_box">Placeholder for broadcast</p></body></html>Now run./manage.py shell.  Import the Turbo Stream and tell the stream to take the current timestamp andupdatethe element with idbroadcast_boxon all subscribed pages.fromquickstart.streamsimportBroadcastStreamfromdatetimeimportdatetimeBroadcastStream().update(text=f"The date and time is now:{datetime.now()}",id="broadcast_box")With thequickstart/path open in a browser window, watch as the broadcast pushes messages to the page.Now change.update()to.append()and resend the broadcast a few times.  Notice you do not have to reload the page to get this modified behavior.Excited to learn more?  Be sure to walk through thetutorialand read more about what Turbo can do for you.DocumentationRead thefull documentationat readthedocs.io.ContributeDiscussions about a Django/Hotwire integration are happening on theHotwire forum. And on Slack, which you can join byclicking here!As this new magic is discovered, you can expect to see a few repositories with experiments and demos appear in@hotwire-django. If you too are experimenting, we encourage you to ask for write access to the GitHub organization and to publish your work in a @hotwire-django repository.LicenseTurbo-Django is released under theMIT Licenseto keep compatibility with the Hotwire project.If you submit a pull request. Remember to add yourself toCONTRIBUTORS.md!