python - django请教下各位,怎么管理生产环境和开发环境的配置
高洛峰
高洛峰 2017-04-18 09:15:41
0
3
451

目前想到两种方式管理配置文件:

1.写两个product_settings.py, development_setting.py, 然后写个build脚本,根据
jenkins 设置构建环境,不同的环境将不同的配置文件软连接或者cp成settings.py

2.线上环境用的是supervisor+gunicorn+nginx+django,gunicorn启东时,可以设置变量,
设置一个DJANGO_RUN_ENV变量,然后在settings.py中通过判断变量的值,更新不同的配置,
但是有一个默认的配置就是线上的。

不知道哪种方式更加合适一些,请大神分享下自己的配置文件管理方式,万分感谢。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
阿神
settings
    --__init__.py
    --common.py
    --dev.py
    --uat.py
    --pro.py
     
common.py里面配置通用部分
dev.py、uat.py、pro.py里面配置开发、测试、生产环境不同的配置
__init__.py里面
from common import *
#from dev import *
#from uat import *
#from pro import *
巴扎黑

This is the first way I use

阿神

Generally, the alpha, beta or production machines of Python projects will uniformly brush the environment required to run the Python project (generally refers to the infrastructure: such as redis, mq, etc.), and you can specially brush an environment-related configuration file (for example: /etc/google/env.yaml), specify the environment to which the current machine belongs (alpah, beta, prod, etc.) in this file, and then you can put a field:

env: alpha/beta/prod

Then your django project configures a module to read the machine environment configuration file.

This method may seem cumbersome, but it is actually very effective in environmental management. This is how we do it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template