diff options
| -rw-r--r-- | fsweb/settings.py | 19 | ||||
| -rw-r--r-- | requirements.txt | 1 | 
2 files changed, 15 insertions, 5 deletions
diff --git a/fsweb/settings.py b/fsweb/settings.py index 956d541..5f02be0 100644 --- a/fsweb/settings.py +++ b/fsweb/settings.py @@ -10,7 +10,9 @@ For the full list of settings and their values, see  https://docs.djangoproject.com/en/5.1/ref/settings/  """ +import os  from pathlib import Path +from dotenv import load_dotenv  # Build paths inside the project like this: BASE_DIR / 'subdir'.  BASE_DIR = Path(__file__).resolve().parent.parent @@ -19,13 +21,20 @@ BASE_DIR = Path(__file__).resolve().parent.parent  # Quick-start development settings - unsuitable for production  # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-!@6fpyap5a=3d@lcv=7hm04534j839ie!*(bz=etm4v_fh&y*b' +env = os.getenv('DJANGO_ENV') +if env == 'production': +    load_dotenv('/var/www/fsweb/config/.env') +else: +    load_dotenv('.env') -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = os.getenv('DEBUG') == 'True' +SECRET_KEY = os.getenv('SECRET_KEY') +ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',') -ALLOWED_HOSTS = [] +if not SECRET_KEY: +    raise ValueError("SECRET_KEY is not set in the .env file") +if env == 'production' and not ALLOWED_HOSTS: +    raise ValueError("ALLOWED_HOSTS must be set in production")  # Application definition diff --git a/requirements.txt b/requirements.txt index 4c4fa9e..9baa87c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ django-stubs==5.2.7  django-stubs-ext==5.2.7  gunicorn==23.0.0  packaging==25.0 +python-dotenv==1.1.1  sqlparse==0.5.3  types-PyYAML==6.0.12.20250915  typing_extensions==4.15.0  | 
