Django HTMX

Starter project for Django, with HTMX, Tailwind and Alpine.js.

1 December 2023

Web development

A starter project for Django based on DjangoX by Will Vincent. This adds a few extra features I found I was adding for every project, as well as switching the front-end framework from Bootstrap and jQuery to Tailwind, HTMX and Alpine.js.

Homepage

↑ Index page showing the logged-in user menu.

Features

Installation

Clone the project and move into the directory.

git clone https://github.com/MattKevan/djangox-tailwind.git
cd djangox-tailwind

Create a new virtual environment and activate it.

python -m venv .venv
source .venv/bin/activate 

Rename env-sample to .env and add your site key as well as any other variables. If necessary, you can generate a site key here.

mv env-sample .env

Install the requirements and set up the database. The site will use SQLite by default, but it's straightforward to use Postgres instead.

pip install -r requirements.txt
python manage.py migrate

Set up the superuser, entering your email, username and password.

$ python manage.py createsuperuser

Launch the site at http://127.0.0.1:8000

$ python manage.py runserver

Tailwind

Open a new terminal tab, ensuring your virtual environment venv is activated. Start the Tailwind development server with:

python manage.py tailwind start

This will watch for changes in your template and theme files and use browsersync to refresh the browser.

Create a build optimised for production:

python manage.py tailwind build

View on Github »