Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
20190211:django settings.py 修改DATABASES, 增加内部IP.
Browse files Browse the repository at this point in the history
Signed-off-by: east4ming <cuikaidong@foxmail.com>
  • Loading branch information
east4ming committed Feb 11, 2019
1 parent dd6695d commit 5dceef6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
44 changes: 32 additions & 12 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions learning_log/database.py
@@ -0,0 +1,28 @@
import os

from django.conf import settings

engines = {
'sqlite': 'django.db.backends.sqlite3',
'postgresql': 'django.db.backends.postgresql_psycopg2',
}


def config():
service_name = os.getenv('DATABASE_SERVICE_NAME', '').upper().replace('-',
'_')
if service_name:
engine = engines.get(os.getenv('DATABASE_ENGINE'), engines['sqlite'])
else:
engine = engines['sqlite']
name = os.getenv('DATABASE_NAME')
if not name and engine == engines['sqlite']:
name = os.path.join(settings.BASE_DIR, 'db.sqlite3')
return {
'ENGINE': engine,
'NAME': name,
'USER': os.getenv('DATABASE_USER'),
'PASSWORD': os.getenv('DATABASE_PASSWORD'),
'HOST': os.getenv('{}_SERVICE_HOST'.format(service_name)),
'PORT': os.getenv('{}_SERVICE_PORT'.format(service_name)),
}
9 changes: 5 additions & 4 deletions learning_log/settings.py
Expand Up @@ -79,11 +79,10 @@
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

from . import database

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
'default': database.config()
}

# Password validation
Expand Down Expand Up @@ -130,3 +129,5 @@
BOOTSTRAP3 = {
'include_jquery': True,
}

INTERNAL_IPS = ['127.0.0.1']

1 comment on commit 5dceef6

@east4ming
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INTERNAL_IPS = ['127.0.0.1'] 没有用到.

Please sign in to comment.