A sane template to use as the starting point when creating Django web apps.
- 🐳 Container-first (using Docker)
- 🎨 Bootstrap 5.3 with django-libsass and django-compressor
- 🏡 There is a single static page (home)
- 📧 Users can register on the site registration with email verification
- 🔐 Change password and forgot password flow in case of forgotten password
- 🔑 Per-record authorization using django-rules
- 📸 Users can upload a profile image
- 🌗 User preferences page to pick between dark mode, light mode, and auto
- 🧪 Tests with Pytest
- 🧪 Code coverage with coverage
- 🐙 GitHub action to automate tests
- 🔃 Pre-commit hooks
-
First, install Poetry.
-
(Optional) Configure Poetry to create a .venv environment in the project:
poetry config virtualenvs.create true poetry config virtualenvs.in-project true
-
Run this (will create a
.venv
folder in the project directory, and this folder is gitignored):poetry install
-
Install pre-commit hooks:
pre-commit install
Before starting the server, copy the contents of file .env.example
to .env
.
This file contains the environment variables and is gitignored.
When making additions/changes to this file, also add the variables to pytest.ini
which passes these to the application when testing.
To save on typing, I have included the following useful scripts:
Command | Description |
---|---|
./scripts/up.sh |
Build and start the server (detached) on localhost:8000 |
./scripts/down.sh |
Stop the server |
./scripts/down_up.sh |
Runs down.sh then up.sh |
./scripts/shell.sh |
Run a Django shell |
./scripts/seed.sh |
Seeds the database |
./scripts/regenerate_db_schema.sh |
Deletes all migrations, makes migrations, migrates and seeds the db |
You can open the scripts to see what they do, but they basically mostly call docker compose
.
Note you can also run the server without Docker with:
python manage.py runserver
poetry shell
pytest
coverage run -m pytest
Followed by:
coverage html