diff options
| author | user@node5.net <user@node5.net> | 2025-12-16 22:04:36 +0100 |
|---|---|---|
| committer | user@node5.net <user@node5.net> | 2025-12-16 22:04:36 +0100 |
| commit | 24d43660b30bd6d51da57fb1d777c8960569f980 (patch) | |
| tree | 82451c33c333516fb6f88de4a2715eb2940d783b /web_interface/django_project/settings.py | |
| parent | 133e9fd4e4248de394c3a846fe15b271dbf7ac55 (diff) | |
Rename django foldermain
Diffstat (limited to 'web_interface/django_project/settings.py')
| -rw-r--r-- | web_interface/django_project/settings.py | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/web_interface/django_project/settings.py b/web_interface/django_project/settings.py new file mode 100644 index 0000000..4f23ce3 --- /dev/null +++ b/web_interface/django_project/settings.py @@ -0,0 +1,189 @@ +""" +Django settings for drinks-machine project. + +Generated by 'django-admin startproject' using Django 6.0. + +For more information on this file, see +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 +import sys + +from django.core.management.utils import get_random_secret_key + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! + +# Define the path to your secret key file inside the .secrets folder +secret_key_file = os.path.join(BASE_DIR, '.secrets', 'secret_key.txt') + +# Ensure the .secrets directory exists +os.makedirs(os.path.dirname(secret_key_file), exist_ok=True) + +# Check if the file exists +if not os.path.exists(secret_key_file): + # Generate a new secret key + secret_key = get_random_secret_key() + + # Save the secret key to the file + with open(secret_key_file, 'w') as f: + f.write(secret_key) +else: + # Read the secret key from the file + with open(secret_key_file, 'r') as f: + secret_key = f.read().strip() + +# Set the SECRET_KEY setting +SECRET_KEY = secret_key + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = "DEBUG" in os.environ and os.environ["DEBUG"] == "INSECURE" +print(f"Debug is: {'on' if DEBUG else 'off'}") + +ALLOWED_HOSTS = ['127.0.0.1', 'drinks-machine.node5.net'] + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'drinks', + 'colorfield', + 'motor_controls', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'django_project.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'django_project.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/6.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/6.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/6.0/howto/static-files/ + +STATIC_URL = '/static/' +#STATIC_ROOT = os.path.join(BASE_DIR, "static") +STATICFILES_DIRS = [BASE_DIR / "static"] + +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "stream": sys.stdout, + "class": "logging.StreamHandler", + "formatter": "verbose", + }, + "syslog": { + "address": "/dev/log", + "class": "logging.handlers.SysLogHandler", + "formatter": "verbose", + }, + }, + "root": { + "handlers": ["console" if DEBUG is True else "syslog"], + "level": "DEBUG", + }, + "loggers": { + "django": { + "handlers": ["console" if DEBUG is True else "syslog"], + "level": "INFO", + "propagate": False, + }, + }, + "formatters": { + "verbose": { + "()": ( + "django_project.ColorLogFormatter.ColorFormatter" + if DEBUG is True + else "django_project.ColorLogFormatter.SysLogColorFormatter" + ), + "format": "{asctime:s} {levelname:8s} {filename}:{lineno:d} \t {message}", + "style": "{", + }, + }, +} |
