good default django settings for deployments

current docker deployment was not taking in account deployment with DOMAIN

- domain is enforced, localhost by default
- .env.example proposed (right now only with DOMAIN)
This commit is contained in:
pedro 2024-09-23 13:09:48 -03:00
parent 2ed33270ed
commit 765b017ac2
3 changed files with 11 additions and 3 deletions

1
.env.example Normal file
View File

@ -0,0 +1 @@
DOMAIN=localhost

View File

@ -27,10 +27,17 @@ BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = "django-insecure-1p8rs@qf$$l^!vsbetagojw23kw@1ez(qi8^(s0t&#7!wyh!l3"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = config('DEBUG', default=False, cast=bool)
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='[]', cast=Csv())
DOMAIN = config("DOMAIN")
assert DOMAIN not in [None, ''], "DOMAIN var is MANDATORY"
# this var is very important, we print it
print("DOMAIN: " + DOMAIN)
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default=DOMAIN, cast=Csv())
assert DOMAIN in ALLOWED_HOSTS, "DOMAIN is not ALLOWED_HOST"
CSRF_TRUSTED_ORIGINS = config('CSRF_TRUSTED_ORIGINS', default=f'https://{DOMAIN}', cast=Csv())
# Application definition

View File

@ -5,7 +5,7 @@ services:
dockerfile: docker/devicehub-django.Dockerfile
environment:
- DEBUG=true
- ALLOWED_HOSTS=*
- DOMAIN=${DOMAIN:-localhost}
volumes:
- .:/opt/devicehub-django
ports: