标签: django-mysql

Django 配置不同的数据库

我有两个database兴趣,基本的和开发的:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| projectsdb         |
| projectsdb_dev     |
+--------------------+
3 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

在我的 django 文件中mysite/mysite/settings.py,我的数据库是这样声明的:

DATABASES = {  
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'projectsdb',
        'USER': 'projectsdb',
        'PASSWORD': 'notsecure',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}
Run Code Online (Sandbox Code Playgroud)

允许的主机是:

ALLOWED_HOSTS = ['xxx.xx.xxx.xx']  # I replaced it for the example
Run Code Online (Sandbox Code Playgroud)

我在用于开发的端口 8006 上启动服务器:

$ python ./manage.py runserver …
Run Code Online (Sandbox Code Playgroud)

django django-database django-settings django-mysql

1
推荐指数
1
解决办法
2836
查看次数