Django

screenshot of Django
django

Our production ready (too much) opinionated django template

Overview

This article introduces a personal Django template that comes with various essential features for building API-only Django applications. The template includes features such as Shields.io maintainability, test coverage, and easy installation. It also provides additional tools like JWT support, pip-tools for managing dependencies, mypy for type checking, and flake8 for code linting. The template uses a custom user model, supports API schema generation, provides additional security using django-axes, and offers effortless hosting of static files using Whitenoise. It is also compatible with cloudflare and includes integration with Sentry for error monitoring. The template is PostgreSQL-ready and suggests optional next steps for further customization and optimization.

Features

  • Shields.io Maintainability Test Coverage: Provides a maintainability test coverage feature using Shields.io.
  • API-only Django: Built specifically for API-only Django applications based on Django REST Framework with JWT support.
  • pip-tools with separate development-time dependencies: Utilizes pip-tools for managing dependencies, including separate development-time dependencies.
  • Strict type checking with mypy, django-stubs, and djangorestframework-stubs: Enforces strict type checking using mypy, django-stubs, and djangorestframework-stubs.
  • flake8 with ton of plugins: Includes flake8 with a wide range of useful plugins for code linting.
  • black as uncompromising code formatter: Uses black as the code formatter for consistent and uniform code formatting.
  • Starter CI configuration on GitHub Actions: Provides a starter CI configuration for GitHub Actions, allowing for easy integration with continuous integration workflows.
  • pytest with useful stuff like freezegun, pytest-mock, and super convenient DRF test client: Utilizes pytest with additional useful tools like freezegun, pytest-mock, and a convenient DRF test client.
  • Custom user model: Supports a custom user model for greater flexibility in user authentication and authorization.
  • drf-spectacular for API Schema generation: Includes drf-spectacular for API schema generation, enabling automatic generation of API documentation.
  • django-axes for additional security: Implements django-axes for additional security measures such as IP tracking and lockouts.
  • Whitenoise for effortless static files hosting: Uses Whitenoise for seamless hosting of static files without the need for a separate server.
  • cloudflare-ready with django-ipware: Supports integration with Cloudflare CDN and utilizes django-ipware for handling client IP addresses correctly.
  • Sentry for error monitoring: Integrates with Sentry for monitoring and tracking errors. It requires setting the SENTRY_DSN environment variable.
  • Postgres ready: Compatible with PostgreSQL databases. Requires setting the DATABASE_URL environment variable.
  • Optional next steps: Provides optional suggestions for further installation and customization steps, including installing pytest-xdist for scaling unit tests and exploring a Docker setup using the provided docker-compose.yml file.

Summary

This article introduces a personal Django template designed for API-only Django applications. The template offers various essential features, including maintainability test coverage, strict type checking, code linting, and a custom user model. Additionally, it provides tools for managing dependencies, generating API schemas, and ensuring additional security. The template also supports effortless hosting of static files, integration with various services like Cloudflare and Sentry, and compatibility with PostgreSQL databases. Optional next steps and suggestions for further customization and optimization are also provided.

django
Django

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It follows the model-view-controller (MVC) architectural pattern, providing an extensive set of built-in tools and conventions to streamline the creation of robust and scalable web applications.