Ticket #35848: settings.py

File settings.py, 2.7 KB (added by Андрей, 4 weeks ago)
Line 
1import os.path
2from pathlib import Path
3
4
5import environ
6from decimal import getcontext, ROUND_HALF_UP
7
8BASE_DIR = Path(__file__).resolve().parent.parent
9env_file = os.path.join(BASE_DIR, ".env.production")
10if not os.path.isfile(env_file):
11 env_file = os.path.join(BASE_DIR, ".env.development")
12if not os.path.isfile(env_file):
13 env_file = os.path.join(BASE_DIR, ".env")
14
15environ.Env.read_env(os.path.join(BASE_DIR, env_file))
16
17getcontext().rounding = ROUND_HALF_UP
18
19env = environ.Env(
20 DEBUG=(bool, False)
21)
22
23DEBUG = bool(env("DJANGO_DEBUG"))
24
25SECRET_KEY = env("DJANGO_SECRET_KEY")
26
27ALLOWED_HOSTS = [
28 ".localhost",
29 "127.0.0.1",
30 "[::1]",
31]
32
33INTERNAL_IPS = [
34 "127.0.0.1",
35]
36
37
38# Application definition
39INSTALLED_APPS = [
40 "daphne",
41 "django.contrib.admin",
42 "django.contrib.auth",
43 "django.contrib.contenttypes",
44 "django.contrib.sessions",
45 "django.contrib.messages",
46 "django.contrib.staticfiles",
47 "django_filters",
48 "rest_framework",
49 "corsheaders",
50 "directories",
51]
52
53MIDDLEWARE = [
54 "django.middleware.security.SecurityMiddleware",
55 "django.contrib.sessions.middleware.SessionMiddleware",
56 "corsheaders.middleware.CorsMiddleware",
57 "django.middleware.common.CommonMiddleware",
58 "django.middleware.csrf.CsrfViewMiddleware",
59 "django.contrib.auth.middleware.AuthenticationMiddleware",
60 "django.contrib.messages.middleware.MessageMiddleware",
61 "django.middleware.clickjacking.XFrameOptionsMiddleware",
62]
63
64ROOT_URLCONF = "backend.urls"
65
66TEMPLATES = [
67 {
68 "BACKEND": "django.template.backends.django.DjangoTemplates",
69 "DIRS": [BASE_DIR / "templates"],
70 "APP_DIRS": True,
71 "OPTIONS": {
72 "context_processors": [
73 "django.template.context_processors.debug",
74 "django.template.context_processors.request",
75 "django.contrib.auth.context_processors.auth",
76 "django.contrib.messages.context_processors.messages",
77 ],
78 },
79 },
80]
81
82WSGI_APPLICATION = "backend.wsgi.application"
83ASGI_APPLICATION = "backend.asgi.application"
84
85STATIC_URL = "staticfiles/"
86STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
87
88# Database
89DATABASES = {
90 "default": {
91 "ENGINE": "django.db.backends.postgresql",
92 "NAME": env("DATABASE_NAME"),
93 "USER": env("DATABASE_USER"),
94 "PASSWORD": env("DATABASE_PASSWORD"),
95 "HOST": env("DATABASE_HOST"),
96 "PORT": env("DATABASE_PORT"),
97 }
98}
99
100# Default primary key field type
101DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
102
103REST_FRAMEWORK = {
104 "DEFAULT_METADATA_CLASS": [
105 "rest_framework.renderers.JSONRenderer",
106 "rest_framework.metadata.SimpleMetadata",
107 ],
108}
109
110CORS_ORIGIN_ALLOW_ALL = True
Back to Top