Skip to content

A Django template using my favorite packages

License

Notifications You must be signed in to change notification settings

rnegron/django-project-template

Repository files navigation

Raúl's Django project template

When I get an idea for a backend project, I want to get up and running quickly with all my favorite packages. Hence this template repository!

About

Inspired by Sergio Mattei's "Shipping Projects at Lightning Speed with Django and NextJS" talk at Fullstack Nights, as well as José Padilla's own project template.

Features

  • Most recent Python (3.12)
  • Latest Django LTS (4.2)
  • poetry as an alternative to pipenv
  • Containerization with Docker
  • Type hints using mypy and django-stubs
  • Tests and linting with GitHub CI
  • A docker-compose setup for easy development using the latest Postgres major version supported by Heroku (15)
  • Static file serving with WhiteNoise
  • Deployment to Heroku using containers
  • Testing with pytest-django
  • Aggressive pre-commit hooks with tools such as black, isort and flake8
  • Argon2 hashed passwords by default
  • Alternative settings layout within a top-level config folder
  • Custom user model with no username (only email/password)
  • Sentry support for error tracking
  • Atomic Requests in production
  • Celery asynchronous task management with Redis as the transport
  • Django Celery Beat for periodic tasks management from the Django Admin
  • htmx support via django-htmx for AJAX and other tools in HTML
  • Tailwind CSS support via django-tailwind for webpage styling
  • Alpine.js support via base template <script> tag for small interactivity

Manual Quickstart

I recommend checking out pipx for isolating management commands like django-admin when working outside a virtual environment.

pipx install 'django==4.2'
django-admin startproject \
    --template=https://github.com/rnegron/django-project-template/archive/main.zip \
    --name=docker-entrypoint.sh,.isort.cfg \
    --extension=py,md,yml \
    project_name_here
cd project_name_here
poetry install
cp .env.example .env
poetry run pre-commit install
poetry run python manage.py check

If not using Docker, you will need to provide your own Postgres database and add the connection URL to the .env file.

Docker Quickstart

pipx install 'django==4.2'
django-admin startproject \
    --template=https://github.com/rnegron/django-project-template/archive/main.zip \
    --name=docker-entrypoint.sh,.isort.cfg \
    --extension=py,md,yml \
    project_name_here
cd project_name_here
cp .env.example .env
docker-compose up --detach --build

The API should be live at http://localhost:8000. A super user for the Django Admin is created automatically using fixtures when using the Docker quickstart method.

    email: [email protected]
    password: password123

Deploy with Heroku

Log in to your Heroku account with their CLI and set up your repository to track your Heroku app. Then,

  • heroku stack:set container
  • git push heroku main

More information: Heroku docs.

Track errors with Sentry

Simply add your Sentry DSN to the .env file.

More information: Sentry docs.