Get a basic blog up and running
[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 json
15 import os
16
17 # Build paths inside the project like this: BASE_DIR / 'subdir'.
18 BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
19
20
21 # Quick-start development settings - unsuitable for production
22 # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
23
24 try:
25     with open(os.path.expanduser('~/.styxrc'), 'r') as styxrc:
26         LOCAL_SETTINGS = json.loads(styxrc.read())
27
28 except FileNotFoundError:
29     LOCAL_SETTINGS = {}
30
31 # SECURITY WARNING: don't run with debug turned on in production!
32 DEBUG = LOCAL_SETTINGS.get('DEBUG', True)
33
34 if DEBUG:
35     SECRET_KEY = 'mq@_9a6&y4nvgqa7obf-r%a4^dt)z=r8jr&91&=oc^6-=i0*$z'
36 else:
37     SECRET_KEY = LOCAL_SETTINGS['SECRET_KEY']
38
39 ALLOWED_HOSTS = [
40     'localhost',
41     'www.localhost',
42     'styx.blog',
43     '46.101.172.187',
44 ]
45
46 # Application definition
47
48 INSTALLED_APPS = [
49     'django.contrib.admin',
50     'django.contrib.auth',
51     'django.contrib.contenttypes',
52     'django.contrib.sessions',
53     'django.contrib.messages',
54     'django.contrib.staticfiles',
55     'core',
56 ]
57
58 MIDDLEWARE = [
59     'django.middleware.security.SecurityMiddleware',
60     'django.contrib.sessions.middleware.SessionMiddleware',
61     'django.middleware.common.CommonMiddleware',
62     'django.middleware.csrf.CsrfViewMiddleware',
63     'django.contrib.auth.middleware.AuthenticationMiddleware',
64     'django.contrib.messages.middleware.MessageMiddleware',
65     'django.middleware.clickjacking.XFrameOptionsMiddleware',
66 ]
67
68 ROOT_URLCONF = 'styx.urls'
69
70 TEMPLATES = [
71     {
72         'BACKEND': 'django.template.backends.django.DjangoTemplates',
73         'DIRS': [],
74         'APP_DIRS': True,
75         'OPTIONS': {
76             'context_processors': [
77                 'django.template.context_processors.debug',
78                 'django.template.context_processors.request',
79                 'django.contrib.auth.context_processors.auth',
80                 'django.contrib.messages.context_processors.messages',
81             ],
82         },
83     },
84 ]
85
86 WSGI_APPLICATION = 'styx.wsgi.application'
87
88
89 # Database
90 # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
91
92 if DEBUG:
93     DATABASES = {
94         'default': {
95             'ENGINE': 'django.db.backends.sqlite3',
96             'NAME': BASE_DIR / 'db.sqlite3',
97         }
98     }
99 else:
100     DATABASES = {
101         'default': {
102             'ENGINE': 'django.db.backends.postgresql_psycopg2',
103             'NAME': 'styx',
104             'USER': 'styxuser',
105             'HOST': 'localhost',
106             'PASSWORD': LOCAL_SETTINGS['DB_PASSWORD'],
107         }
108     }
109
110
111 # Password validation
112 # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
113
114 AUTH_PASSWORD_VALIDATORS = [
115     {
116         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
117     },
118     {
119         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
120     },
121     {
122         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
123     },
124     {
125         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
126     },
127 ]
128
129
130 # Internationalization
131 # https://docs.djangoproject.com/en/3.1/topics/i18n/
132
133 LANGUAGE_CODE = 'en-us'
134
135 TIME_ZONE = 'UTC'
136
137 USE_I18N = True
138
139 USE_L10N = True
140
141 USE_TZ = True
142
143
144 # Static files (CSS, JavaScript, Images)
145 # https://docs.djangoproject.com/en/3.1/howto/static-files/
146
147 STATIC_URL = '/static/'
148 STATIC_ROOT = os.path.join(BASE_DIR, 'static/')