Chinaunix首页 | 论坛 | 博客
  • 博客访问: 177884
  • 博文数量: 32
  • 博客积分: 553
  • 博客等级: 中士
  • 技术积分: 369
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-17 18:18
文章分类

全部博文(32)

文章存档

2015年(1)

2014年(1)

2013年(9)

2012年(9)

2011年(12)

分类: 系统运维

2011-06-30 07:50:48

由于自己要在不同的机器上进行开发,而且采用的是CVS控制版本,

有时候主机自己有MySQL环境,有时候又要连接到另外一台数据库服务器,setting里面
数据库主机地址就需要自己动态更改,很不方便,我就在setting上动了一个小手脚,这样
setting文件会根据不同的主机类型自动选择用什么作为DB服务器的地址,这样就不需要
每次手动更改setting文件了.很方便.具体实现如下
  1. def choose_db():
  2.     platform_ = ' '
  3.     
  4.     platform_host = platform.platform()
  5.     platform_ = platform_host[:20]
  6.     
  7.     if platform_ == 'Windows-2008ServerR2':
  8.         db_host = '192.168.1.122'
  9.     else:
  10.         db_host = 'localhost'
  11.     
  12.     return db_host

  13. DB_HOST = choose_db()

  14. DATABASES = {
  15.     'default': {
  16.         'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
  17.         'NAME': 'test', # Or path to database file if using sqlite3.
  18.         'USER': 'test', # Not used with sqlite3.
  19.         'PASSWORD': '123456', # Not used with sqlite3.
  20.         'HOST': DB_HOST, # Set to empty string for localhost. Not used with sqlite3.
  21.         'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
  22.     }
  23. }

阅读(1436) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~