Skip to content

Commit

Permalink
Install dj-database-url
Browse files Browse the repository at this point in the history
  • Loading branch information
tm-kn committed Nov 12, 2024
1 parent 81396f2 commit 8272b23
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
profile=black
sections=FUTURE,STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
known_first_party=config
known_django=django
default_section=THIRDPARTY
42 changes: 19 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,22 @@ docker compose exec dev format

In addition to the [base Docker image variables](https://github.com/nationalarchives/docker/blob/main/docker/tna-python-django/README.md#environment-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_ |
| 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_URL` | The database's URL (`postgres://USER:PASSWORD@HOST:PORT/NAME`) | _none_ |
| `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_ |
1 change: 1 addition & 0 deletions config/jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.templatetags.static import static
from django.urls import reverse

from jinja2 import Environment


Expand Down
14 changes: 4 additions & 10 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pathlib import Path
from sysconfig import get_path

import dj_database_url

from config.util import strtobool

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -69,16 +71,8 @@
# Database
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": os.environ.get("DATABASE_NAME", ""),
"USER": os.environ.get("DATABASE_USER", ""),
"PASSWORD": os.environ.get("DATABASE_PASSWORD", ""),
"HOST": os.environ.get("DATABASE_HOST", ""),
"PORT": os.environ.get("DATABASE_PORT", "5432"),
}
}
DATABASES = {"default": dj_database_url.config(conn_max_age=600)}


# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
Expand Down
6 changes: 1 addition & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ services:
- DJANGO_SETTINGS_MODULE=config.settings.develop
- SECRET_KEY=abc123
- NPM_DEVELOP_COMMAND=dev
- DATABASE_NAME=postgres
- DATABASE_USER=postgres
- DATABASE_PASSWORD=postgres
- DATABASE_HOST=db
- DATABASE_PORT=5432
- DATABASE_URL=postgres://postgres:postgres@db:5432/postgres
- DJANGO_SUPERUSER_PASSWORD=admin
- DJANGO_SUPERUSER_USERNAME=admin
- COOKIE_DOMAIN=localhost
Expand Down
30 changes: 28 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ django = "^5.0.7"
psycopg2-binary = "^2.9.9"
django-csp = "^3.8"
whitenoise = "^6.7.0"
dj-database-url = "^2.3.0"

[tool.poetry.group.dev]
optional = true
Expand Down

0 comments on commit 8272b23

Please sign in to comment.