Skip to content

nationalarchives/django-application-template

Repository files navigation

TNA Python Flask Application

Quickstart

# Build and start the container
docker compose up -d

# Install Node modules
npm install

# Create a static assets directory
mkdir app/static/assets

# Copy in the TNA Frontend static assets
cp -r node_modules/@nationalarchives/frontend/nationalarchives/assets/* app/static/assets

Run tests

docker compose exec dev poetry run python manage.py test

Format and lint code

docker compose exec dev format

Environment variables

In addition to the base Docker image variables, this application has support for:

Variable Purpose Default
DJANGO_SETTINGS_MODULE The configuration to use config.settings.production
ALLOWED_HOSTS A comma-separated list of allowed hosts none on production and staging, * on develop and test
USE_X_FORWARDED_HOST Use the X-Forwarded-Host header in preference to Host False
DEBUG If true, allow debugging False
COOKIE_DOMAIN The domain to save cookie preferences against none
DATABASE_NAME The name of the Postgres database none
DATABASE_USER The username needed to access the Postgres database none
DATABASE_PASSWORD The password needed to access the Postgres database none
DATABASE_HOST The Postgres database host none
DATABASE_PORT The Postgres database port 5432
CSP_IMG_SRC A comma separated list of CSP rules for img-src 'self'
CSP_SCRIPT_SRC A comma separated list of CSP rules for script-src 'self'
CSP_SCRIPT_SRC_ELEM A comma separated list of CSP rules for script-src-elem 'self'
CSP_STYLE_SRC A comma separated list of CSP rules for style-src 'self'
CSP_STYLE_SRC_ELEM A comma separated list of CSP rules for style-src-elem 'self'
CSP_FONT_SRC A comma separated list of CSP rules for font-src 'self'
CSP_CONNECT_SRC A comma separated list of CSP rules for connect-src 'self'
CSP_MEDIA_SRC A comma separated list of CSP rules for media-src 'self'
CSP_WORKER_SRC A comma separated list of CSP rules for worker-src 'self'
CSP_FRAME_SRC A comma separated list of CSP rules for frame-src 'self'
GA4_ID The Google Analytics 4 ID none