![管理多个settings.py文件[重复],第1张 管理多个settings.py文件[重复],第1张](/aiimages/%E7%AE%A1%E7%90%86%E5%A4%9A%E4%B8%AAsettings.py%E6%96%87%E4%BB%B6%5B%E9%87%8D%E5%A4%8D%5D.png)
我使用的设置模块不是单个文件:
settings/ __init__.py _base.py _servers.py development.py production.py testing.py
该
__init__.py文件很简单:
from _servers import get_server_typeexec("from %s import *" % get_server_type())该
_base.py文件包含所有服务器类型的所有通用设置。
该
_servers.py文件中包含一个函数
get_server_type()使用
socket.gethostname()来确定当前的机器是什么类型的服务器:它返回
development,
production或
testing。
然后其他文件看起来有点像(
production.py):
DEBUG=FalseTEMPLATE_DEBUG=Falsefrom _base import *
在每个这些文件中,我都输入了仅适用于此服务器类型的设置。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)