How to Setup a GRUG Stack Environment
The GRUG stack is a development environment used for building Hypermedia-Driven Applications. It consists of:
- A web framework backend like Django
- HTMX
- _hyperscript
- TailwindCSS
Some people prefer to substitute Alpine.js for _hyperscript. While technically different, they both occupy the same place in the GRUG stack. I'll teach how to install both.
The Fastest Way
If you just want to try the whole stack out fast, install Django (or your choice of backend frameworks) and then make
a base.html
template that looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
You are now ready to develop the latest Hypermedia-Driven Applications.
However, if you want to make an environment that you can later use in production, follow the rest of this tutorial.
Summary
For the busy developer:
- Install software
pip install ...
- Follow their install and configuration procedures.
- django-tailwind provides a
base.html
template. Add the _hyperscript or Alpine.js scripts to the head of the HTML.
Your base.html
file should look like this when you're finished:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Detailed Instructions
After installing everything via pip
, continue with the following:
Make new app
python manage.py startapp core
Make static directory
Make a directory called static
in the core
app directory.
Make a directory called core
in the static
app directory (yes, really).
We'll use this directory later. Still more setup to do.
Make templates directory
Make a directory called templates
in the core
app.
Make a directory called core
in the templates
folder (stop asking questions, grug).
We'll use this directory later. Still more setup to do.
Add to INSTALLED_APPS
1 2 3 4 5 6 7 8 9 10 11 12 |
|
HTMX: Add Middleware
1 2 3 4 5 6 |
|
HTMX: Download and add to static folder
- Download HTMX here
- Put it in the
core
app's static directory (you will put it incore/static/core/htmx.min.js
)
We're done with HTMX for now.
Tailwind: Create Tailwind CSS app
Run django-tailwind initialization script.
python manage.py tailwind init
Follow instructions. Use default name theme
for app.
Tailwind: Modify settings.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Tailwind: Install TailwindCSS dependencies
python manage.py tailwind install
Tailwind: Add django_browser_reload
to urls.py
1 2 3 4 5 6 7 8 9 |
|
When we created the theme
app with python manage.py tailwind init
,
django-tailwind
very kindly provided us a base.html
file in the theme/templates
folder.
Let's edit it.
Final setup
The default base.html
file provided by django-tailwind
looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
We need to add HTMX and _hyperscript (or Alpine.js) to this file. Under {% load static tailwind_tags %}
, add two more
lines:
1 2 |
|
Inside <head>
, under {% tailwind_css %}
, add:
1 2 |
|
This is the only install step for _hyperscript (or Alpine.js).
Your base.html
file should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
Phew! Setup complete, grug brother. You are now ready to start building your next Hypermedia-Driven Application.
One last thing
We didn't touch on why we installed django-widget-tweaks
and django-render-block
.
In a future guide you will see a practical example of how these are used and why they are part of the GRUG stack development environment. To put it simply:
django-widget-tweaks
lets us style Django forms in the template, rather than in theforms.py
file. That allows us to follow the principle of Locality of Behavior. It also makes using Tailwind much easier.django-render-block
similarly lets us include template fragments inside main template files, again allowing us to follow the principle of Locality of Behavior.
Because much of the action in a Hypermedia-Driven Application is in the hypermedia (i.e. HTML), it's important to install these two Django extensions to make working in Django templates easier.
Author
Added
Nov. 29, 2023