Background
As you know, React, Vue and other frontend techs (Angular, Svelte) are becoming more and more popular nowadays.
In most cases, when people use the above techs, Django will work as an API server, for example, expose data to JSON API using Django REST framework
.
However, some people (including me) do not like the above approach, and they want a simple solution:
- They like to use classic Django form, Django templates, Django standard auth.
- Do not split the frontend and backend to keep infrastructure simple.
- Render HTML in Django, and use Javascript to enhance the server-rendred HTML.
Why I recommend Hotwire
If you do some research, you will see there are already some solutions such as:
- HTMX
- Alpine.js
- Unicorn
I prefer Hotwire because:
- It is the official frontend solution in Rails and is very popular in the PHP community.
- It has healthy ecosystem, there are many tutorials, blog, videos and open source projects on Github for us to use directly and learn.
- It can let us write less Javascript while getting things done quickly.
- Hotwire can help you keep frontend code clean and easy to maintain.
- Hotwire can even help you to build
hybrid
mobile apps, it gives you a complete solution across all platforms.
If you want to know more about the lightweight Javascript framework, you can check my previous article:
Lightweight Javascript Framework Review (For Django Developers)
Objectives
Considering there are no good tutorials about Hotwire and Django.
I decided to write a book to help people to learn Hotwire with Django in a systematic way and now it is published.
After reading this book, you will be able to:
- Learn Howtwire includes
Turbo
andStimulus
, and what problem they can help solve. - Jump start frontend project bundled by Webpack.
- Use Tailwind CSS as your theme solution.
- Setup Turbo and Stimulus.
- Learn how page navigation works in
Turbo Drive
- Understand what is cache in Turbo Drive and how preview works.
- Learn what is
Turbo Frame
and how it works. - Build
Inline Editing
feature withTurbo Frame
. - Learn what is
Stimulus
and howStimulus Controller
work. - What is Stimulus
Values
,Targes
, andActions
- Use Stimulus to build a Datetime picker and improve form submission process.
- Understand how to use events to do communication among Stimulus controllers
- Build
Type as search
feature with Stimulus, Turbo and Django. - Learn what is
Turbo Stream
and how it works. - How to build
Collaborative Editing
based on Websocket andTurbo Stream
Tech
- Django
- Django channels
- Hotwire
- Tailwind CSS
What is included
- A PDF ebook which contains about 40 chapters.
- The source code of the project.
Demo
The demo is available on https://hotwire-django.fly.dev/
Table of contents
- Introduction
- Create Project
- Setup Turbo
- Create Task App
- Render Django Form with Tailwind CSS Style
- Explore Turbo Drive (Page Navigation)
- Explore Turbo Drive (Cache)
- Explore Turbo Drive (Javascript, CSS)
- Explore Turbo Drive (3-party Javascript)
- Turbo Drive and Django form validation
- Prepare to Learn Turbo Frame
- Turbo Frame Basics
- Turbo Frame and Django Form
- Inline Editing with Turbo Frames
- Prepare Django app to learn Stimulus Basics
- Stimulus Controller Basics
- Stimulus Controller (Actions, Values)
- Stimulus Controller (Targets, CSS classes)
- Stimulus Controller (Lifecycle)
- Stimulus Controller (3-party Resources)
- Stimulus Controller (Date Picker)
- Stimulus Controller (Form Submission)
- Prepare Django app to learn Stimulus and Turbo Frame
- Stimulus Controller (Flash Message)
- Build Stimulus Controller for Modal
- Load Form in the Modal
- Handle Form Submission in Modal
- Full Page Redirect in Modal
- Communication Among Stimulus Controllers Via Events
- Prepare Django app to learn Stimulus Stream
- Import Turbo Frame
- Turbo Stream Basics
- Use Turbo Stream to improve inline editing
- Filtering on the List Page
- Auto Search
- RealTime Update based on Websocket (Part 1)
- RealTime Update based on Websocket (Part 2)
- Next Steps