feat: Store database credentials in a separate configuration file
This commit is contained in:
parent
a774ae23eb
commit
b65fd05fb1
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -22,3 +22,6 @@ db.sqlite3-journal
|
|||
# OS-specific files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Database configuration
|
||||
config/database.ini
|
||||
|
|
|
|||
6
config/database.ini
Normal file
6
config/database.ini
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[postgresql]
|
||||
host=barad-dur.lan.mgk.one
|
||||
database=leadsdb
|
||||
user=melkor
|
||||
password=Th3leetnis!leadsdb
|
||||
port=5433
|
||||
|
|
@ -12,10 +12,15 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
|
|||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import configparser
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
# Read database configuration
|
||||
config = configparser.ConfigParser()
|
||||
config.read(os.path.join(BASE_DIR, 'config', 'database.ini'))
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
|
|
@ -78,11 +83,11 @@ WSGI_APPLICATION = 'leadsdb.wsgi.application'
|
|||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'leadsdb',
|
||||
'USER': 'melkor',
|
||||
'PASSWORD': 'Th3leetnis!leadsdb',
|
||||
'HOST': 'barad-dur.lan.mgk.one',
|
||||
'PORT': '5433',
|
||||
'NAME': config['postgresql']['database'],
|
||||
'USER': config['postgresql']['user'],
|
||||
'PASSWORD': config['postgresql']['password'],
|
||||
'HOST': config['postgresql']['host'],
|
||||
'PORT': config['postgresql']['port'],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue