django 线上线下使用不同的数据库 上线:mysql 线下sqlite3 以及debug模式的开和关

 

 

hostname = socket.gethostname() 获取主机名称

import os
import socket

hostname = socket.gethostname()
if hostname == '2121vbbqbnh4ug2pq2d0zn3Z':
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',  # 默认
            'NAME': 'mfor_photo_files',  # mysql的库名称
            'USER': 'user_mfor',  # 用户名
            'PASSWORD': '$Pucr@503',  # 密码
            'HOST': 'rm-8vb5n9t5tz62235txto.mysql.zhangbei.rds.aliyuncs.com',  # 默认
            'PORT': '3306',  # 默认
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }

 

 

hostname = socket.gethostname()
if hostname == '2121212':
    DEBUG = False
else:
    DEBUG = True

 

posted on 2018-02-23 11:12  星河赵  阅读(249)  评论(0编辑  收藏  举报

导航