This repository has been archived by the owner on Jul 31, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20190211:django settings.py 修改DATABASES, 增加内部IP.
Signed-off-by: east4ming <cuikaidong@foxmail.com>
- Loading branch information
Showing
3 changed files
with
65 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5dceef6
There was a problem hiding this comment.
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'] 没有用到.