Configure for the server
[styx.blog] / styx / settings.py
1 """
2 Django settings for styx project.
3
4 Generated by 'django-admin startproject' using Django 3.1.
5
6 For more information on this file, see
7 https://docs.djangoproject.com/en/3.1/topics/settings/
8
9 For the full list of settings and their values, see
10 https://docs.djangoproject.com/en/3.1/ref/settings/
11 """
12
13 from pathlib import Path
14 import os
15
16 # Build paths inside the project like this: BASE_DIR / 'subdir'.
17 BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
18
19
20 # Quick-start development settings - unsuitable for production
21 # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
22
23 # SECURITY WARNING: keep the secret key used in production secret!
24
25 # SECURITY WARNING: don't run with debug turned on in production!
26 DEBUG = (os.environ.get('STYX_DEBUG', 'true') == 'true')
27
28 if DEBUG:
29     SECRET_KEY = 'mq@_9a6&y4nvgqa7obf-r%a4^dt)z=r8jr&91&=oc^6-=i0*$z'
30 else:
31     SECRET_KEY = os.environ['STYX_SECRET_KEY']
32
33 ALLOWED_HOSTS = [
34     'localhost',
35     'www.localhost',
36     'styx.blog',
37     '46.101.172.187',
38 ]
39
40 # Application definition
41
42 INSTALLED_APPS = [
43     'django.contrib.admin',
44     'django.contrib.auth',
45     'django.contrib.contenttypes',
46     'django.contrib.sessions',
47     'django.contrib.messages',
48     'django.contrib.staticfiles',
49 ]
50
51 MIDDLEWARE = [
52     'django.middleware.security.SecurityMiddleware',
53     'django.contrib.sessions.middleware.SessionMiddleware',
54     'django.middleware.common.CommonMiddleware',
55     'django.middleware.csrf.CsrfViewMiddleware',
56     'django.contrib.auth.middleware.AuthenticationMiddleware',
57     'django.contrib.messages.middleware.MessageMiddleware',
58     'django.middleware.clickjacking.XFrameOptionsMiddleware',
59 ]
60
61 ROOT_URLCONF = 'styx.urls'
62
63 TEMPLATES = [
64     {
65         'BACKEND': 'django.template.backends.django.DjangoTemplates',
66         'DIRS': [],
67         'APP_DIRS': True,
68         'OPTIONS': {
69             'context_processors': [
70                 'django.template.context_processors.debug',
71                 'django.template.context_processors.request',
72                 'django.contrib.auth.context_processors.auth',
73                 'django.contrib.messages.context_processors.messages',
74             ],
75         },
76     },
77 ]
78
79 WSGI_APPLICATION = 'styx.wsgi.application'
80
81
82 # Database
83 # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
84
85 if DEBUG:
86     DATABASES = {
87         'default': {
88             'ENGINE': 'django.db.backends.sqlite3',
89             'NAME': BASE_DIR / 'db.sqlite3',
90         }
91     }
92 else:
93     DATABASES = {
94         'default': {
95             'ENGINE': 'django.db.backends.postgresql_psycopg2',
96             'NAME': 'styx',
97             'USER': 'styxuser',
98             'PASSWORD': os.environ['STYX_DB_PASSWORD'],
99         }
100     }
101
102
103 # Password validation
104 # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
105
106 AUTH_PASSWORD_VALIDATORS = [
107     {
108         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
109     },
110     {
111         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
112     },
113     {
114         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
115     },
116     {
117         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
118     },
119 ]
120
121
122 # Internationalization
123 # https://docs.djangoproject.com/en/3.1/topics/i18n/
124
125 LANGUAGE_CODE = 'en-us'
126
127 TIME_ZONE = 'UTC'
128
129 USE_I18N = True
130
131 USE_L10N = True
132
133 USE_TZ = True
134
135
136 # Static files (CSS, JavaScript, Images)
137 # https://docs.djangoproject.com/en/3.1/howto/static-files/
138
139 STATIC_URL = '/static/'
140 STATIC_ROOT = os.path.join(BASE_DIR, 'static/')