■ ■ ■ ■ ■ ■
race_condition_playground/settings.py
| 1 | + | """ |
| 2 | + | Django settings for race_condition_playground project. |
| 3 | + | |
| 4 | + | Generated by 'django-admin startproject' using Django 3.1.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 | + | import os |
| 14 | + | import dj_database_url |
| 15 | + | from pathlib import Path |
| 16 | + | |
| 17 | + | PROJECT_SLUG = 'race_condition_playground' |
| 18 | + | # Build paths inside the project like this: BASE_DIR / 'subdir'. |
| 19 | + | BASE_DIR = Path(__file__).resolve().parent.parent |
| 20 | + | |
| 21 | + | |
| 22 | + | # Quick-start development settings - unsuitable for production |
| 23 | + | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ |
| 24 | + | |
| 25 | + | # SECURITY WARNING: keep the secret key used in production secret! |
| 26 | + | SECRET_KEY = os.environ.get('SECRET_KEY', 'secret') |
| 27 | + | |
| 28 | + | # SECURITY WARNING: don't run with debug turned on in production! |
| 29 | + | DEBUG = os.environ.get('DEBUG') in ('true', 'True', '1', 'TRUE', 'on', 'ON') |
| 30 | + | |
| 31 | + | ALLOWED_HOSTS = ['*'] |
| 32 | + | |
| 33 | + | |
| 34 | + | # Application definition |
| 35 | + | |
| 36 | + | INSTALLED_APPS = [ |
| 37 | + | 'django.contrib.admin', |
| 38 | + | 'django.contrib.auth', |
| 39 | + | 'django.contrib.contenttypes', |
| 40 | + | 'django.contrib.sessions', |
| 41 | + | 'django.contrib.messages', |
| 42 | + | 'django.contrib.staticfiles', |
| 43 | + | 'django_bootstrap5', |
| 44 | + | 'app.ucenter', |
| 45 | + | ] |
| 46 | + | |
| 47 | + | MIDDLEWARE = [ |
| 48 | + | 'django.middleware.security.SecurityMiddleware', |
| 49 | + | 'django.contrib.sessions.middleware.SessionMiddleware', |
| 50 | + | 'django.middleware.common.CommonMiddleware', |
| 51 | + | 'django.middleware.csrf.CsrfViewMiddleware', |
| 52 | + | 'django.contrib.auth.middleware.AuthenticationMiddleware', |
| 53 | + | 'django.contrib.messages.middleware.MessageMiddleware', |
| 54 | + | 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
| 55 | + | ] |
| 56 | + | |
| 57 | + | ROOT_URLCONF = PROJECT_SLUG + '.urls' |
| 58 | + | |
| 59 | + | TEMPLATES = [ |
| 60 | + | { |
| 61 | + | 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
| 62 | + | 'DIRS': [ |
| 63 | + | BASE_DIR / 'templates' |
| 64 | + | ], |
| 65 | + | 'APP_DIRS': True, |
| 66 | + | 'OPTIONS': { |
| 67 | + | 'context_processors': [ |
| 68 | + | 'django.template.context_processors.debug', |
| 69 | + | 'django.template.context_processors.request', |
| 70 | + | 'django.contrib.auth.context_processors.auth', |
| 71 | + | 'django.contrib.messages.context_processors.messages', |
| 72 | + | ], |
| 73 | + | }, |
| 74 | + | }, |
| 75 | + | ] |
| 76 | + | |
| 77 | + | WSGI_APPLICATION = PROJECT_SLUG + '.wsgi.application' |
| 78 | + | |
| 79 | + | AUTH_USER_MODEL = 'ucenter.User' |
| 80 | + | |
| 81 | + | # Database |
| 82 | + | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases |
| 83 | + | |
| 84 | + | DATABASES = { |
| 85 | + | 'default': dj_database_url.config(default='sqlite:///' + str(BASE_DIR / 'data' / 'sqlite3' / 'db.sqlite3')) |
| 86 | + | } |
| 87 | + | |
| 88 | + | |
| 89 | + | # Password validation |
| 90 | + | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators |
| 91 | + | |
| 92 | + | AUTH_PASSWORD_VALIDATORS = [ |
| 93 | + | { |
| 94 | + | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', |
| 95 | + | }, |
| 96 | + | { |
| 97 | + | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', |
| 98 | + | }, |
| 99 | + | { |
| 100 | + | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', |
| 101 | + | }, |
| 102 | + | { |
| 103 | + | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', |
| 104 | + | }, |
| 105 | + | ] |
| 106 | + | |
| 107 | + | |
| 108 | + | # Internationalization |
| 109 | + | # https://docs.djangoproject.com/en/3.1/topics/i18n/ |
| 110 | + | |
| 111 | + | LANGUAGE_CODE = 'en-us' |
| 112 | + | |
| 113 | + | TIME_ZONE = 'Asia/Singapore' |
| 114 | + | |
| 115 | + | USE_I18N = True |
| 116 | + | |
| 117 | + | USE_L10N = True |
| 118 | + | |
| 119 | + | USE_TZ = True |
| 120 | + | |
| 121 | + | CACHES = { |
| 122 | + | 'default': { |
| 123 | + | 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', |
| 124 | + | 'LOCATION': BASE_DIR / 'data' / 'cache', |
| 125 | + | } |
| 126 | + | } |
| 127 | + | |
| 128 | + | LOGGING = { |
| 129 | + | 'version': 1, |
| 130 | + | 'disable_existing_loggers': False, |
| 131 | + | 'formatters': { |
| 132 | + | 'standard': { |
| 133 | + | 'format': '[%(asctime)s] - [%(levelname)s] - [%(pathname)s:%(lineno)d] - %(message)s', |
| 134 | + | 'datefmt': '%Y-%m-%d %H:%M:%S' |
| 135 | + | }, |
| 136 | + | 'sample': { |
| 137 | + | 'format': '[%(asctime)s] - %(message)s', |
| 138 | + | 'datefmt': '%Y-%m-%d %H:%M:%S' |
| 139 | + | }, |
| 140 | + | }, |
| 141 | + | 'handlers': { |
| 142 | + | 'console': { |
| 143 | + | 'level': 'DEBUG', |
| 144 | + | 'class': 'logging.StreamHandler', |
| 145 | + | 'formatter': 'standard', |
| 146 | + | 'filters': ['discard_not_found_error'], |
| 147 | + | }, |
| 148 | + | 'file': { |
| 149 | + | 'level': 'DEBUG', |
| 150 | + | 'class': 'logging.FileHandler', |
| 151 | + | 'filename': BASE_DIR / 'data' / 'logs' / 'django.log', |
| 152 | + | 'filters': ['discard_not_found_error'], |
| 153 | + | 'formatter': 'standard' |
| 154 | + | } |
| 155 | + | }, |
| 156 | + | 'loggers': { |
| 157 | + | '': { |
| 158 | + | 'handlers': ['console', 'file'], |
| 159 | + | 'level': 'WARNING' |
| 160 | + | }, |
| 161 | + | 'django': { |
| 162 | + | 'handlers': ['console', 'file'], |
| 163 | + | 'level': 'WARNING', |
| 164 | + | 'propagate': False |
| 165 | + | }, |
| 166 | + | }, |
| 167 | + | 'filters': { |
| 168 | + | 'discard_not_found_error': { |
| 169 | + | '()': 'django.utils.log.CallbackFilter', |
| 170 | + | 'callback': lambda record: (not hasattr(record, 'status_code')) or |
| 171 | + | (hasattr(record, 'status_code') and not (400 <= record.status_code < 500)), |
| 172 | + | } |
| 173 | + | }, |
| 174 | + | } |
| 175 | + | |
| 176 | + | # Static files (CSS, JavaScript, Images) |
| 177 | + | # https://docs.djangoproject.com/en/3.1/howto/static-files/ |
| 178 | + | |
| 179 | + | STATIC_URL = '/static/' |
| 180 | + | STATIC_ROOT = BASE_DIR / 'data' / 'static' |
| 181 | + | MEDIA_URL = '/media/' |
| 182 | + | MEDIA_ROOT = BASE_DIR / 'data' / 'media' |
| 183 | + | |
| 184 | + | |
| 185 | + | SESSION_COOKIE_AGE = 60 * 60 * 24 * 180 |
| 186 | + | SECURE_REFERRER_POLICY = 'origin-when-cross-origin' |
| 187 | + | # SESSION_COOKIE_SECURE = not DEBUG |
| 188 | + | # CSRF_COOKIE_SECURE = not DEBUG |
| 189 | + | # SECURE_SSL_REDIRECT = not DEBUG |
| 190 | + | # SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') |
| 191 | + | X_FRAME_OPTIONS = 'deny' |
| 192 | + | |
| 193 | + | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
| 194 | + | |