|
""" |
|
Django settings for quizsite project. |
|
|
|
Generated by 'django-admin startproject' using Django 4.1.1. |
|
|
|
For more information on this file, see |
|
https://docs.djangoproject.com/en/4.1/topics/settings/ |
|
|
|
For the full list of settings and their values, see |
|
https://docs.djangoproject.com/en/4.1/ref/settings/ |
|
""" |
|
|
|
import os |
|
from pathlib import Path |
|
|
|
import environ |
|
|
|
env = environ.Env( |
|
|
|
DEBUG=(bool, False), |
|
DBENGINE=(str, "django.db.backends.postgresql_psycopg2"), |
|
DBSSL=(str, "disable"), |
|
ADMIN_URL=(str, "admin/"), |
|
STATIC_BACKEND=(str, "django.contrib.staticfiles.storage.StaticFilesStorage"), |
|
) |
|
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent |
|
|
|
|
|
environ.Env.read_env(os.path.join(BASE_DIR.parent, ".env")) |
|
|
|
|
|
|
|
|
|
|
|
SECRET_KEY = env("SECRET_KEY") |
|
|
|
|
|
DEBUG = env("DEBUG") |
|
|
|
DEBUG_PROPAGATE_EXCEPTIONS = env("DEBUG") |
|
|
|
|
|
|
|
if env.get_value("WEBSITE_HOSTNAME", default=None): |
|
ALLOWED_HOSTS = [os.environ["WEBSITE_HOSTNAME"]] |
|
CSRF_TRUSTED_ORIGINS = ["https://" + os.environ["WEBSITE_HOSTNAME"]] |
|
else: |
|
ALLOWED_HOSTS = [] |
|
CSRF_TRUSTED_ORIGINS = [ |
|
"http://localhost:8000", |
|
"https://mq-django-quiz-app.vercel.app", |
|
"https://mq-quiz.teddysc.me", |
|
"https://teddysc.me", |
|
"https://tddschn-mq-quiz.hf.space", |
|
"http://tddschn-mq-quiz.hf.space", |
|
] |
|
if env.get_value("CODESPACE_NAME", default=None): |
|
CSRF_TRUSTED_ORIGINS.append( |
|
f"https://{env('CODESPACE_NAME')}-8000.{env('GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN')}" |
|
) |
|
|
|
ALLOWED_HOSTS = [ |
|
"localhost", |
|
"mq-django-quiz-app.vercel.app", |
|
"mq-quiz.teddysc.me", |
|
"teddysc.me", |
|
"g.teddysc.me", |
|
"tddschn-mq-quiz.hf.space", |
|
] |
|
ADMIN_URL = env("ADMIN_URL") |
|
|
|
|
|
|
|
INSTALLED_APPS = [ |
|
"markdownify.apps.MarkdownifyConfig", |
|
"quizzes.apps.QuizzesConfig", |
|
"django.contrib.admin", |
|
"django.contrib.auth", |
|
"django.contrib.contenttypes", |
|
"django.contrib.sessions", |
|
"django.contrib.messages", |
|
"whitenoise.runserver_nostatic", |
|
"django.contrib.staticfiles", |
|
] |
|
|
|
MIDDLEWARE = [ |
|
"django.middleware.security.SecurityMiddleware", |
|
"whitenoise.middleware.WhiteNoiseMiddleware", |
|
"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 = "quizsite.urls" |
|
|
|
TEMPLATES = [ |
|
{ |
|
"BACKEND": "django.template.backends.django.DjangoTemplates", |
|
"DIRS": [], |
|
"APP_DIRS": True, |
|
"OPTIONS": { |
|
"context_processors": [ |
|
"django.template.context_processors.debug", |
|
"django.template.context_processors.request", |
|
"django.contrib.auth.context_processors.auth", |
|
"django.contrib.messages.context_processors.messages", |
|
], |
|
}, |
|
}, |
|
] |
|
|
|
WSGI_APPLICATION = "quizsite.wsgi.application" |
|
|
|
|
|
|
|
|
|
|
|
DATABASES = { |
|
"default": { |
|
"ENGINE": "quizsite.postgresql", |
|
"NAME": env("DBNAME"), |
|
"HOST": env("DBHOST"), |
|
"USER": env("DBUSER"), |
|
"PASSWORD": env("DBPASS", default="PASSWORD_WILL_BE_SET_LATER"), |
|
"OPTIONS": {"sslmode": env("DBSSL")}, |
|
"CONN_MAX_AGE": 60 * 60 * 6, |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
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", |
|
}, |
|
] |
|
|
|
|
|
|
|
|
|
|
|
LANGUAGE_CODE = "en-us" |
|
|
|
TIME_ZONE = "America/Los_Angeles" |
|
|
|
USE_I18N = True |
|
|
|
USE_TZ = True |
|
|
|
|
|
|
|
|
|
|
|
STATIC_URL = "static/" |
|
|
|
|
|
STORAGES = { |
|
"staticfiles": { |
|
"BACKEND": env("STATIC_BACKEND"), |
|
}, |
|
} |
|
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") |
|
|
|
|
|
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
|
|
|
ALLOWED_HOSTS = [ |
|
"localhost", |
|
"mq-django-quiz-app.vercel.app", |
|
"mq-quiz.teddysc.me", |
|
"teddysc.me", |
|
"g.teddysc.me", |
|
"tddschn-mq-quiz.hf.space", |
|
"huggingface.com", |
|
] |
|
|
|
CSRF_TRUSTED_ORIGINS = [ |
|
"http://localhost:8000", |
|
"https://mq-django-quiz-app.vercel.app", |
|
"https://mq-quiz.teddysc.me", |
|
"https://teddysc.me", |
|
"https://tddschn-mq-quiz.hf.space", |
|
"http://tddschn-mq-quiz.hf.space", |
|
"https://*.teddysc.me", |
|
"https://*.huggingface.com", |
|
] |
|
|