ソースを参照

switch db to postgres

Prach Pongpanich 2 年 前
コミット
274e984a3a
共有1 個のファイルを変更した13 個の追加3 個の削除を含む
  1. 13 3
      app/tmt_learning/settings.py

+ 13 - 3
app/tmt_learning/settings.py

11
 """
11
 """
12
 
12
 
13
 from pathlib import Path
13
 from pathlib import Path
14
+import os
15
+import environ
14
 
16
 
15
 # Build paths inside the project like this: BASE_DIR / 'subdir'.
17
 # Build paths inside the project like this: BASE_DIR / 'subdir'.
16
 BASE_DIR = Path(__file__).resolve().parent.parent
18
 BASE_DIR = Path(__file__).resolve().parent.parent
17
 
19
 
20
+env = environ.Env()
21
+environ.Env.read_env()
22
+
18
 
23
 
19
 # Quick-start development settings - unsuitable for production
24
 # Quick-start development settings - unsuitable for production
20
 # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
25
 # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
25
 # SECURITY WARNING: don't run with debug turned on in production!
30
 # SECURITY WARNING: don't run with debug turned on in production!
26
 DEBUG = True
31
 DEBUG = True
27
 
32
 
28
-ALLOWED_HOSTS = []
33
+ALLOWED_HOSTS = ['*']
29
 
34
 
30
 
35
 
31
 # Application definition
36
 # Application definition
75
 
80
 
76
 DATABASES = {
81
 DATABASES = {
77
     'default': {
82
     'default': {
78
-        'ENGINE': 'django.db.backends.sqlite3',
79
-        'NAME': BASE_DIR / 'db.sqlite3',
83
+        'ENGINE': 'django.db.backends.postgresql_psycopg2',
84
+        'NAME': env("POSTGRES_NAME"),
85
+        'USER': env("POSTGRES_USER"),
86
+        'PASSWORD': env("POSTGRES_PASSWORD"),
87
+        'HOST': 'db',
88
+        'PORT': '5432',
80
     }
89
     }
81
 }
90
 }
82
 
91
 
83
 
92
 
93
+
84
 # Password validation
94
 # Password validation
85
 # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
95
 # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
86
 
96