Load settings from .env file.

This commit is contained in:
krek0 2026-04-24 21:42:23 +02:00
parent f221740228
commit 3efa217716
4 changed files with 31 additions and 13 deletions

View file

@ -14,6 +14,7 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
import os
from decouple import Csv, config
from django.contrib.messages import constants as messages
from django.utils.translation import gettext_lazy as _
@ -25,17 +26,12 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "CHANGE ME"
SECRET_KEY = config("SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
DEBUG = config("DEBUG", default=False, cast=bool)
ALLOWED_HOSTS = [
"127.0.0.1",
"localhost",
"photos.crans.org",
"photos-dev.crans.org",
]
ALLOWED_HOSTS = ["127.0.0.1", "localhost"] + config("EXTRA_HOSTS", default="", cast=Csv())
INTERNAL_IPS = [
"127.0.0.1",
@ -43,9 +39,8 @@ INTERNAL_IPS = [
]
# Admins receive server errors, this is useful to be notified of potential bugs
ADMINS = [
("admin", "photos-admin@lists.crans.org"),
]
# Format: "Name:email,Name2:email2"
ADMINS = [tuple(a.split(":")) for a in config("ADMINS", default="", cast=Csv()) if a]
# Use secure cookies in production
SESSION_COOKIE_SECURE = not DEBUG
@ -204,7 +199,7 @@ if DEBUG:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# Mail will be sent from this address
SERVER_EMAIL = "photos@crans.org"
SERVER_EMAIL = config("SERVER_EMAIL", default="photos@crans.org")
DEFAULT_FROM_EMAIL = f"Serveur photos <{SERVER_EMAIL}>"
EMAIL_SUBJECT_PREFIX = "[Serveur photos] "