Skip to main content

Default configuration and components for Django projects.

Project description

Kition Django Defaults

CI PyPI PyPI - Python Version PyPI - License

This package provides default configuration and components for Django projects.

Motivation

Building, operating and maintaining many Django applications leads to repetitive code. This repository strives to reduce the mental overhead by providing code that otherwise would have to be repeated.

Installation

Requirements

Python 3.12 and Django 5.1 supported.

Installation

  1. Install with pip:
    python -m pip install kition-djangodefaults
    
  2. Start your applications settings file with the default setting initialization
    from kition_djangodefaults import initialize_default_settings
    
    initialize_default_settings(__name__)
    
  3. (Optional) configure any of the following components.

Consider explicitly listing the dependencies of kition-djangodefaults in your project to pin specific versions of Django, psycopg and others.

Kubernetes Readiness Endpoint Middleware

Install via

MIDDLEWARE = [
    # Putting the healthcheck middleware first to circumvent ALLOWED_HOSTS protections, which would fail Kubernetes
    # Readiness Probe requests.
    "kition_django_defaults.healthcheck.HealthCheckMiddleware",
    ...
]

Development

poetry env use $(pyenv which python)
poetry install
poetry run python -m unittest

Provided Configuration

The following section describe the general behaviour of setting groups, while not trying to be exhaustive. Check the code for details. Environment variables are listed for non-Django people.

General

The settings resolve the BASEDIR to be the grandparent of the applications settings file, which usually is the projects root directory.

Name Description Value
DEBUG Enable the Django debug mode to print additional error information. false
SECRET_KEY A secret key used for cryptographic signing. Has to be unique and unpredictable. 64 character length recommended. return value of Djangos get_random_secret_key()

Network

Name Description Value
ALLOWED_HOST Hostname or domain name that the application is allowed to serve. Prevents HTTP Host header attacks. localhost
TLS_ENABLED Flag to enable or disable TLS/SSL settings for secure connections. Typically set to true in production. false
SECURE_PROXY_SSL_HEADER_NAME The name of the HTTP header used by the proxy to indicate that the original request was made via HTTPS. X-Forwarded-Proto
SECURE_PROXY_SSL_HEADER_VALUE The value for the SECURE_PROXY_SSL_HEADER_NAME that confirms the request was secure (HTTPS). https
SECURE_HSTS_SECONDS The duration in seconds that the browser should enforce HTTPS via the HTTP Strict Transport Security (HSTS) policy. 3600
SECURE_HSTS_INCLUDE_SUBDOMAINS A flag indicating whether to apply HSTS to all subdomains as well. false
SECURE_HSTS_PRELOAD A flag indicating whether the application should be included in browsers' HSTS preload lists. false

Database

The application connects to a locally hosted Postgres by default.

Name Description Value
DATABASE_NAME The name of the database used by the application. app
DATABASE_USER The username used to authenticate and connect to the database. postgres
DATABASE_PASSWORD The password associated with the database user for authentication. app
DATABASE_HOST The hostname or IP address where the database server is located. localhost
DATABASE_PORT The port used to connect to the database server, commonly 5432 for PostgreSQL. 5432

Storage and Staticfiles

Name Description Value
OBJECT_STORAGE_ENABLED Determines whether object storage is enabled. If disabled, files will be stored at path BASEDIR/media/. false
STORAGE_BUCKET_NAME The name of the storage bucket where files will be stored. app
STORAGE_ENDPOINT The URL endpoint for accessing the object storage. The URL has to be accessible by the backend and clients. http://localhost:9000
STORAGE_REGION The geographic region of the storage service, commonly used in cloud environments like AWS S3 to specify the location of the bucket. eu-central-1
AWS_S3_ACCESS_KEY_ID The access key ID used to authenticate requests to the object storage service. ""
AWS_S3_SECRET_ACCESS_KEY The secret access key used alongside the access key ID to authenticate and securely interact with the object storage. ""

E-Mail

Name Description Value
DEFAULT_FROM_EMAIL The default email address to use for email notifications sent by the application. noreply@example.com
EMAIL_HOST The host server that will send the email, typically an external SMTP server. localhost
EMAIL_PORT The port used to connect to the email host, 1025 for local development or standard SMTP ports like 587. 1025
EMAIL_USE_TLS Specifies whether the email transmission should use TLS encryption. false
EMAIL_HOST_USER The username for authenticating with the email host. ""
EMAIL_HOST_PASSWORD The password for authenticating with the email host. ""

Background Tasks via django-q2

If django_q is available

  • a default configuration using the DjangoORM is applied and
  • the sendtestmail management command allows sending via a background task.

You are able to install the dependency via the worker extra.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kition_djangodefaults-0.5.0rc1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kition_djangodefaults-0.5.0rc1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file kition_djangodefaults-0.5.0rc1.tar.gz.

File metadata

  • Download URL: kition_djangodefaults-0.5.0rc1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.6 Darwin/24.0.0

File hashes

Hashes for kition_djangodefaults-0.5.0rc1.tar.gz
Algorithm Hash digest
SHA256 3cb0d1a28ae42fdd946d5626e0ece29000e27e4217a80197b737f360ecbbe502
MD5 64402c666f8be7d142a28a82579c7c45
BLAKE2b-256 860671f838946f25d9cd957e4d998fe6401806925c5975d58c43ebcb12af0ce8

See more details on using hashes here.

File details

Details for the file kition_djangodefaults-0.5.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for kition_djangodefaults-0.5.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 48306f71635ee5a7fc4f40ee037aa457502b7f0ef29ffcc2754733d824fea561
MD5 58895ba30d2a0d65b1cbc165330a6402
BLAKE2b-256 4323d5479a6a6075b68193e0967f81beefd49ccffc6033425f67ed1a63a01c1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page