Restructure of settings.py
This commit is contained in:
parent
067bc744d7
commit
e5ffbc9005
@ -5,33 +5,22 @@ from pathlib import Path
|
|||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
now = timezone.now()
|
# BASE_DIR is the root of the project, all paths should be constructed from it using pathlib
|
||||||
env = environ.Env(
|
|
||||||
# set casting, default value
|
|
||||||
DEBUG=(bool, True)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
||||||
# BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|
||||||
BASE_DIR = Path(__file__).parent.parent
|
BASE_DIR = Path(__file__).parent.parent
|
||||||
CORE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
print(BASE_DIR, CORE_DIR)
|
|
||||||
|
|
||||||
# Take environment variables from .env file
|
# Create an environment and read variables from .env file
|
||||||
|
env = environ.Env(DEBUG=(bool, True))
|
||||||
environ.Env.read_env(BASE_DIR / ".env")
|
environ.Env.read_env(BASE_DIR / ".env")
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: This is sensitive data, keep secure!
|
||||||
SECRET_KEY = env('SECRET_KEY', default='S#perS3crEt_007')
|
SECRET_KEY = env('SECRET_KEY', default="unsecure-default-secret-key")
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: Must be 'False' in production!
|
||||||
DEBUG = env('DEBUG')
|
DEBUG = env('DEBUG')
|
||||||
|
|
||||||
# Assets Management
|
# Hosts and Origins that the server host must be within.
|
||||||
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
|
ALLOWED_HOSTS = ["localhost", "127.0.0.1", env("HOST", default="127.0.0.1")]
|
||||||
|
CSRF_TRUSTED_ORIGINS = ["http://localhost", "http://127.0.0.1", "https://" + env("HOST", default="127.0.0.1")]
|
||||||
# load production server from .env
|
|
||||||
ALLOWED_HOSTS = ['localhost', 'localhost:85', '127.0.0.1', '192.168.0.19', env('SERVER', default='127.0.0.1') ]
|
|
||||||
CSRF_TRUSTED_ORIGINS = ['http://localhost:85', 'http://127.0.0.1', 'https://' + env('SERVER', default='127.0.0.1') ]
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
@ -62,14 +51,18 @@ MIDDLEWARE = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'core.urls'
|
ROOT_URLCONF = 'core.urls'
|
||||||
LOGIN_REDIRECT_URL = "home" # Route defined in home/urls.py
|
APPEND_SLASH = True
|
||||||
LOGOUT_REDIRECT_URL = "home" # Route defined in home/urls.py
|
|
||||||
TEMPLATE_DIR = os.path.join(CORE_DIR, "apps/templates") # ROOT dir for templates
|
LOGIN_URL = "/login/"
|
||||||
|
LOGIN_REDIRECT_URL = "/"
|
||||||
|
LOGOUT_REDIRECT_URL = "/"
|
||||||
|
|
||||||
|
AUTH_USER_MODEL = "authentication.User"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [TEMPLATE_DIR],
|
'DIRS': [BASE_DIR / "apps/templates"],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
@ -77,7 +70,6 @@ TEMPLATES = [
|
|||||||
'django.template.context_processors.request',
|
'django.template.context_processors.request',
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
'apps.context_processors.cfg_assets_root',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -85,8 +77,9 @@ TEMPLATES = [
|
|||||||
|
|
||||||
WSGI_APPLICATION = 'core.wsgi.application'
|
WSGI_APPLICATION = 'core.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
|
||||||
|
|
||||||
if os.environ.get('DB_ENGINE') and os.environ.get('DB_ENGINE') == "mysql":
|
if os.environ.get('DB_ENGINE') and os.environ.get('DB_ENGINE') == "mysql":
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
@ -108,7 +101,7 @@ else:
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
{
|
{
|
||||||
@ -125,7 +118,8 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
# Loggiong
|
# Logging
|
||||||
|
# https://docs.djangoproject.com/en/5.0/topics/logging/
|
||||||
|
|
||||||
LOGGING_DIR = BASE_DIR / "logs"
|
LOGGING_DIR = BASE_DIR / "logs"
|
||||||
LOGGING_DIR.mkdir(exist_ok=True)
|
LOGGING_DIR.mkdir(exist_ok=True)
|
||||||
@ -137,7 +131,7 @@ LOGGING = {
|
|||||||
'file': {
|
'file': {
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
'class': 'logging.FileHandler',
|
'class': 'logging.FileHandler',
|
||||||
'filename': LOGGING_DIR / f'{now}.log',
|
'filename': LOGGING_DIR / f'{timezone.now()}.log',
|
||||||
"formatter": "verbose",
|
"formatter": "verbose",
|
||||||
},
|
},
|
||||||
'console': {
|
'console': {
|
||||||
@ -181,8 +175,9 @@ LOGGING = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
# https://docs.djangoproject.com/en/5.0/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-gb'
|
LANGUAGE_CODE = 'en-gb'
|
||||||
|
|
||||||
@ -190,29 +185,26 @@ TIME_ZONE = 'Europe/London'
|
|||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
USE_L10N = True
|
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
#############################################################
|
|
||||||
# SRC: https://devcenter.heroku.com/articles/django-assets
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/1.9/howto/static-files/
|
# https://docs.djangoproject.com/en/5.0/howto/static-files/
|
||||||
STATIC_ROOT = os.path.join(CORE_DIR, 'staticfiles')
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
# Extra places for collectstatic to find static files.
|
# Extra places for collectstatic to find static files.
|
||||||
STATICFILES_DIRS = (
|
STATICFILES_DIRS = (
|
||||||
os.path.join(CORE_DIR, 'apps/static'),
|
BASE_DIR / 'apps/static',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Media Files
|
# Media Files
|
||||||
MEDIA_ROOT = os.path.join(CORE_DIR, 'media')
|
MEDIA_ROOT = BASE_DIR / 'media'
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = '/media/'
|
||||||
|
|
||||||
#############################################################
|
|
||||||
#############################################################
|
# Django Rest Framework
|
||||||
|
# https://www.django-rest-framework.org/
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLE_CLASSES': [
|
'DEFAULT_THROTTLE_CLASSES': [
|
||||||
@ -224,13 +216,3 @@ REST_FRAMEWORK = {
|
|||||||
'user': '1000/day'
|
'user': '1000/day'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################################################
|
|
||||||
#############################################################
|
|
||||||
|
|
||||||
# If route isnt found, try again with appended slash
|
|
||||||
APPEND_SLASH = True
|
|
||||||
|
|
||||||
AUTH_USER_MODEL = "authentication.User"
|
|
||||||
|
|
||||||
LOGIN_URL = "/login/"
|
|
Loading…
x
Reference in New Issue
Block a user