|
9 | 9 | For the full list of settings and their values, see |
10 | 10 | https://docs.djangoproject.com/en/4.0/ref/settings/ |
11 | 11 | """ |
12 | | -import os.path |
| 12 | +import os |
13 | 13 | from pathlib import Path |
14 | 14 |
|
15 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. |
|
86 | 86 |
|
87 | 87 | # Database |
88 | 88 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases |
89 | | - |
90 | | - |
91 | | -DATABASES = { |
92 | | - "default": { |
93 | | - "ENGINE": "django.db.backends.sqlite3", |
94 | | - "NAME": BASE_DIR / "db.sqlite3", |
| 89 | +if os.getenv("AWS_PSQL_HOST"): |
| 90 | + DATABASES = { |
| 91 | + "default": { |
| 92 | + "ENGINE": "django.db.backends.postgresql", |
| 93 | + "HOST": os.getenv("AWS_PSQL_HOST"), |
| 94 | + "PORT": os.getenv("AWS_PSQL_PORT", "5432"), |
| 95 | + "NAME": os.getenv("AWS_PSQL_DATABASE"), |
| 96 | + "USER": os.getenv("AWS_PSQL_USER_ID"), |
| 97 | + "PASSWORD": os.getenv("AWS_PSQL_PW"), |
| 98 | + } |
| 99 | + } |
| 100 | +else: |
| 101 | + DATABASES = { |
| 102 | + "default": { |
| 103 | + "ENGINE": "django.db.backends.sqlite3", |
| 104 | + "NAME": BASE_DIR / "db.sqlite3", |
| 105 | + } |
95 | 106 | } |
96 | | -} |
97 | 107 |
|
98 | 108 |
|
99 | 109 | # Password validation |
|
130 | 140 | # Static files (CSS, JavaScript, Images) |
131 | 141 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ |
132 | 142 |
|
133 | | -STATIC_URL = "static/" |
134 | | - |
135 | | -# S3 |
136 | | -DEFAULT_FILE_STORAGE = ( |
137 | | - "pyconweb2022.customBoto3Storage.SecurityTokenWorkaroundS3Boto3Storage" |
138 | | -) |
139 | | -STATICFILES_STORAGE = "storages.backends.s3boto3.S3StaticStorage" |
140 | | -AWS_S3_SESSION_PROFILE = "pycon" |
141 | | -AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STATIC_S3_BUCKET") |
| 143 | +STATIC_URL = "/static/" |
| 144 | +STATIC_ROOT = BASE_DIR / "staticfiles" |
| 145 | +MEDIA_URL = "/media/" |
| 146 | +MEDIA_ROOT = BASE_DIR / "media" |
| 147 | + |
| 148 | +if os.getenv("AWS_STATIC_S3_BUCKET"): |
| 149 | + DEFAULT_FILE_STORAGE = ( |
| 150 | + "pyconweb2022.customBoto3Storage.SecurityTokenWorkaroundS3Boto3Storage" |
| 151 | + ) |
| 152 | + STATICFILES_STORAGE = "storages.backends.s3boto3.S3StaticStorage" |
| 153 | + AWS_S3_SESSION_PROFILE = "pycon" |
| 154 | + AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STATIC_S3_BUCKET") |
| 155 | + |
| 156 | + STORAGES = { |
| 157 | + "default": { |
| 158 | + "BACKEND": "pyconweb2022.customBoto3Storage.SecurityTokenWorkaroundS3Boto3Storage", |
| 159 | + }, |
| 160 | + "staticfiles": { |
| 161 | + "BACKEND": "storages.backends.s3boto3.S3StaticStorage", |
| 162 | + }, |
| 163 | + } |
| 164 | +else: |
| 165 | + STORAGES = { |
| 166 | + "default": { |
| 167 | + "BACKEND": "django.core.files.storage.FileSystemStorage", |
| 168 | + }, |
| 169 | + "staticfiles": { |
| 170 | + "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage", |
| 171 | + }, |
| 172 | + } |
142 | 173 |
|
143 | 174 | # Default primary key field type |
144 | 175 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field |
|
0 commit comments