Commit f255bf7a by Xu Zhou

using env for mysql pass.

parent 6822f3a7
...@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/ ...@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
""" """
import os import os
import sys
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
...@@ -74,13 +75,23 @@ WSGI_APPLICATION = 'Hunter_ht.wsgi.application' ...@@ -74,13 +75,23 @@ WSGI_APPLICATION = 'Hunter_ht.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
def get_env_value(env_variable):
try:
return os.environ[env_variable]
except KeyError:
error_msg = 'Set the {} environment variable'.format(env_variable)
print (error_msg)
sys.exit(-1)
MYSQL_USER = get_env_value('MYSQL_USER')
MYSQL_PASS = get_env_value('MYSQL_PASS')
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.mysql', 'ENGINE': 'django.db.backends.mysql',
'NAME': 'HUNTER', 'NAME': 'HUNTER',
'USER': 'root', 'USER': MYSQL_USER,
'PASSWORD': 'mysql', 'PASSWORD': MYSQL_PASS,
'HOST': 'localhost', 'HOST': 'localhost',
'PORT': '3306', 'PORT': '3306',
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment