我有三个设置文件:
- base.py (共享)
- development.py
- production.py
base.py 包含以下内容:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes'
...
但我有一些只想在开发环境中使用的应用程序,例如debug-toolbar
。
我在development.py中尝试了以下方法:
INSTALLED_APPS += (
'debug_toolbar',
)
但出现错误:
NameError: name 'INSTALLED_APPS' is not defined
设置文件连接方式如下:
__init__.py
from .base import *
try:
from .production import *
except:
from .development import *
我要如何区分已经安装的应用程序是在生产环境还是开发环境中?
DJANGO_SETTINGS_MODULE=project_name.settings.production
中进行设置,并在production.py
中使用from .base import *
来覆盖需要更改的任何设置即可。 - jackotonye