From 2ebc57fa98df26f7142c6c7c376d1c640ee1b440 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 9 Feb 2026 18:49:23 +0100 Subject: [PATCH] change settings.py variable for .env config file --- project/settings.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/project/settings.py b/project/settings.py index 776ffd2..76573e3 100644 --- a/project/settings.py +++ b/project/settings.py @@ -10,7 +10,12 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ +import os from pathlib import Path +from dotenv import load_dotenv + +# Lädt die Variablen aus der .env Datei +load_dotenv() # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -20,12 +25,12 @@ BASE_DIR = Path(__file__).resolve().parent.parent # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-#xh(_vl!ccdoop$+6@ze-g%%o9dn%ks(b!2c0=w)rxq25p5(p%' +SECRET_KEY = os.getenv('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = os.getenv('DEBUG') == 'True' -ALLOWED_HOSTS = ["gd.pi.lan"] +ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost').split(',') # Application definition @@ -86,12 +91,12 @@ WSGI_APPLICATION = 'project.wsgi.application' DATABASES = { "default": { - "ENGINE": "django.db.backends.mysql", - "NAME": "hansolo_django_gd", - "USER": "hansolo_django_gd", - "PASSWORD": "Django123", - "HOST": "localhost", - "PORT": "3306", + 'ENGINE': "django.db.backends.mysql", + 'NAME': os.getenv('DB_NAME'), + 'USER': os.getenv('DB_USER'), + 'PASSWORD': os.getenv('DB_PASSWORD'), + 'HOST': os.getenv('DB_HOST'), + 'PORT': os.getenv('DB_PORT'), "OPTIONS": { "init_command": "SET sql_mode='STRICT_TRANS_TABLES'", },