Skip to content

A comprehensive and easy-to-use starting point for your new API with Django and DRF

License

Notifications You must be signed in to change notification settings

wilfredinni/django-starter-template

Repository files navigation

Django starter template

A comprehensive and easy-to-use starting point for your new API with Django and DRF.

Test Status CodeQL Status MIT License

Key features

This template includes battle-tested features for building secure, scalable, and maintainable APIs

Core Features

Database & Caching

  • 💿 Pre-configured PostgreSQL database
  • 📦 Redis caching system
  • 🗄️ BaseModel with created_at and updated_at fields
  • 🗑️ Optional SoftDeleteBaseModel for soft deletions

Authentication & Users

  • 🔒 Complete auth system using Knox
  • 🙋 Extended user model with email-based authentication

Task Management

  • Celery for async tasks with BaseTaskWithRetry
  • 🗃️ Task results storage with django_celery_results
  • 📅 Task scheduling through django_celery_beat

Development Tools

  • 🧪 Testing with Pytest
  • ⚡ Interactive development using Jupyter Notebooks
  • 🐞 Debugging with Django Debug Toolbar
  • 🔧 Code quality tools: Black, Flake8
  • 👨‍💻 VS Code with Dev Containers

Additional Features

  • 🔽 Advanced filtering with django-filter
  • 🧩 Extended functionality with Django Extensions

Requirements

  • 💻 VS Code
  • 🐋 Docker
  • 🐳 Docker Compose

How to use

  1. Use GitHub's template feature (recommended) or clone repository and delete the .git folder.
  2. Open the project in VS Code.
  3. If you installed the recommended extensions, open Todo Tree in the sidebar. It will guide you trough the first steps setting up your project, like changing the name of the container, adjusting your URLS, etc.
  4. Hit CTL/CMD + Shift + p and select Reopen in container. This will:
    • Create a dev container.
    • Setup a Redis server.
    • Setup your PostgreSQL database.
    • Add a development .env file.
    • Install the dependencies.
    • Migrate the database.
  5. Create your super user with python manage.py createsuperuser.
  6. Run the project with python manage.py reserver.
  7. Work as usual.

Commands

This template comes with some shortcuts so you don't have to memorize how to start the workers:

  • poetry run worker: to start a new Celery worker.
  • poetry run beat: to start your periodic tasks.

You can also use:

  • poetry run server instead of python manage.py runserver
  • poetry run makemigrations instead of python manage.py makemigrations
  • poetry run migrate instead of python manage.py migrate
  • poetry run create_dev_env to create a development .env file

Todo

  • Index Page with a link to the Django admin
  • OpenAPI 3 schema generation and Swagger.
  • CI with Github Actions
  • Add method to restore soft deleted data
  • Email sending with celery
  • Data seeding
  • API Versioning
  • Production Docker file
  • Production Docker compose file
  • CD with Github Actions