From 96b97e0401ab0dbd2a6e617601168f95a2248c80 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Sun, 15 Feb 2026 21:29:07 +0100 Subject: [PATCH] added .env file --- .env.example | 11 +++++++++++ .gitignore | 6 ++---- backend/holy_backend/settings.py | 27 +++++++++++++++++---------- docker-compose.yml | 2 ++ 4 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2fdf59a --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# Example SMTP Configuration for Holy Flavors +# Rename this file to .env and fill in your details to enable email sending. + +# --- Required for SMTP --- +EMAIL_HOST=smtp.example.com +EMAIL_PORT=587 +EMAIL_HOST_USER=your-email@example.com +EMAIL_HOST_PASSWORD=your-app-password + +# --- Optional (defaults are usually fine) --- +# EMAIL_USE_TLS=true diff --git a/.gitignore b/.gitignore index 1b7c8a5..b6a7fb0 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,5 @@ Thumbs.db # Environment variables .env -.env.local -.env.development.local -.env.test.local -.env.production.local +.env.* +!.env.example diff --git a/backend/holy_backend/settings.py b/backend/holy_backend/settings.py index 5f05f67..d0fba1d 100644 --- a/backend/holy_backend/settings.py +++ b/backend/holy_backend/settings.py @@ -9,8 +9,9 @@ https://docs.djangoproject.com/en/6.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/6.0/ref/settings/ """ - from pathlib import Path +import os + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -147,16 +148,22 @@ CORS_ALLOWED_ORIGINS = [ "http://127.0.0.1:5173", ] +import os +# ... (near top of file) + # Email (SMTP) -# For development, print to console. -# In production, set these via environment variables. -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' -# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' -# EMAIL_HOST = 'smtp.example.com' -# EMAIL_PORT = 587 -# EMAIL_USE_TLS = True -# EMAIL_HOST_USER = 'user' -# EMAIL_HOST_PASSWORD = 'password' +# For production, set these via environment variables. +# For development, it will default to printing emails to the console. +EMAIL_HOST = os.environ.get('EMAIL_HOST') +EMAIL_PORT = int(os.environ.get('EMAIL_PORT', 587)) +EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', 'true').lower() == 'true' +EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER') +EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') + +if EMAIL_HOST: + EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +else: + EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Swagger SPECTACULAR_SETTINGS = { diff --git a/docker-compose.yml b/docker-compose.yml index 9b7ce6b..46aa30c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,8 @@ services: context: ./backend ports: - "8000:8000" + env_file: + - ./.env volumes: - ./backend:/app environment: