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