A starter project for Django with Docker, PostgreSQL, HTMX, and more.
uv
installed on your machine.Clone the repository:
git clone https://github.com/yourusername/django-starter.git
cd django-starter
Install pre-commit hooks:
uv run pre-commit install
Set up environment variables:
Simply copy-paste the .env.example
and adjust where necessary. For generating a secret key, you can run this:
uv run python -c "import secrets; print(''.join(secrets.choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_+)') for i in range(50)))"
Copy the output and paste it into the .env
file.
Start the Docker environment:
docker compose up -d
This will automatically apply migrations, create a superuser (if credentials are provided in the .env
file), and collect static files.
Access the application:
While the entrypoint script handles initial setup tasks, you may need to run other management commands during development:
Make Migrations: After making changes to your models, run:
docker compose exec app python manage.py makemigrations
Apply Migrations: To apply new migrations:
docker compose exec app python manage.py migrate
Create Superuser: If you need to create a superuser manually:
docker compose exec app python manage.py createsuperuser
Run Tests:
docker compose exec app pytest
Collect Static Files:
docker compose exec app python manage.py collectstatic --noinput
Note that you could alias docker compose exec app python manage.py
to dmanage
by adding this to your Powershell profile (code $PROFILE
):
function dmanage {
param(
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$args
)
docker compose exec app python manage.py $args
}
Install frontend dependencies:
cd node
npm install
Run Tailwind in watch mode:
npm run build
Minify CSS and collect static for production:
npm run minify
cd .. && docker compose exec app python manage.py collectstatic --noinput
To debug the application with VSCode using Docker Compose:
Start Services in Debug Mode:
docker compose -f docker-compose.yml -f docker-compose.debug.yml up --build
Attach Debuggers in VSCode:
F5
.F5
.Note: Both services will wait for the debugger to attach before starting.
This setup allows you to debug both the Django application and the Celery worker effectively.
If you prefer to run without Docker, you will need to set up a PostgreSQL database locally and update your .env
file accordingly. Follow these steps:
uv run python manage.py migrate
uv run python manage.py createsuperuser
uv run python manage.py runserver
For email notifications to work, you need to:
.env
file.If you want to use Google's SMTP server, you need to create an app password for the account you want to use and add it to the .env
file.
docker compose exec app pytest
uv run ruff check .
uv run ruff format --check .
.env
file.docker compose logs
to view logs and troubleshoot issues.