Skip to content

Django 5+, Django Rest Framework, Redis/Celery and more

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.

Key features

  • 🧪 Fully tested with Pytest.
  • 🚀 Enjoy the latest version of Django (5+) with all its features and improvements.
  • 🌐 Django Rest Framework for building APIs.
  • ⛃ Start your project with PostgreSQL without the need to install and configure it.
  • 📦 Redis caching out of the box.
  • 🔒 Login, Logout, Logout all, User profile and creation with Knox, an easy-to-use authentication for DRF.
  • 👤 Extended user model and a custom manager with the email as the unique identifier. Define your own fields and behaviors specific to your application's requirements.
  • 🔢 A custom BaseModel to easily add created_at and updated_at fields to your models.
  • 🔢 A custom SoftDeleteBaseModel to add soft delete functionality to the models you choose to.
  • 🕒 Fully configured asynchronous tasks with Celery. It also includes a reusable BaseTaskWithRetry.
  • 🕑 django_celery_results enables Celery to store task results using Django's database backend.
  • 📅 django_celery_beat for periodic task scheduling using the Django admin interface.
  • 🌪️ django-filter add support for complex filtering of querysets in Django and DRF views.
  • Test your queries and code interactively with Jupyter Notebooks.
  • 🐞 Django Debug Toolbar for debugging and profiling and Django Extensions for custom management commands and model enhancements.
  • 👨‍💻 Develop with VS Code and Dev Containers. Get out of the box code formatting with Black, linting with Flake8 and test with Pytest.

Requirements

  • </> VS Code
  • 🐋 Docker
  • 🐳 Docker Compose

How to use

  1. Clone the repo or use it as a template to start a new project. Use as template
  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. todo
  4. Use env.example to create a .env file.
  5. Hit CTL/CMD + Shift + p and select Reopen in container. This will:
    • Create a dev container.
    • Install the dependencies.
    • Setup your PostgreSQL database.
    • Setup a Redis server.
    • Migrate the database.
  6. Create your super user with python manage.py createsuperuser.
  7. Run the project with python manage.py reserver.
  8. 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.

And if you feel like it, 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

Todo

  • Index Page with a link to the Django admin
  • Data seeding
  • API Versioning
  • OpenAPI 3 schema auto generation and Swagger
  • Production Docker file
  • Production Docker compose file
  • CI/CD with Github Actions