管理多个settings.py文件 [英] Managing multiple settings.py files

查看:202
本文介绍了管理多个settings.py文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/1626326/how-to-manage-local-vs-production-settings-in-django\">How管理本地VS Django的生产设置?

我设法与的mod_wsgi 成功部署的 Django项目 Apache的Web服务器

I have managed to deploy successfully a Django project on Apache's Web Server with mod_wsgi.

我想就如何管理多个 settings.py 文件的一些建议。现在我有一个用于开发,一个用于生产(关于DB参数,静态内容本地化,和类似的东西)完全不同。我的 settings.py 文件版本(不知道这是一个很好的做法),我喜欢的东西部署:

I would like some recommendations on how to manage multiple settings.py files. Right now I have one for development and one totally different for production (regarding DB parameters, static content localization, and stuff like that). My settings.py file is versioned (don't know if this is a good practise) and I deploy it with something like:

$ hg archive myproject.tbz2
$ cd /path/of/apache/web/project/location
$ bzip2 -db /home/myself/myproject/myproject.tbz2 | tar -xvf -

它的工作确定。但我发现自己操纵多个 settings.py 文件。

我想我的问题是:什么时候部署的最佳实践的 DJANGO项目有关多个 settings.py 文件版本

I guess my question is: what are the best practices when deploying DJANGO PROJECTS regarding multiple settings.py file versions?

推荐答案

我用设置模块,不是一个单一的文件:

I use a settings module that is not a single file:

settings/
    __init__.py
    _base.py
    _servers.py
    development.py
    production.py
    testing.py

__ __初始化PY 文件很简单:

from _servers import get_server_type
exec("from %s import *" % get_server_type())

_base.py 文件包含了所有的常用设置跨越所有服务器类型。

The _base.py file contains all of the common settings across all server types.

_servers.py 文件包含一个函数 get_server_type()使用插座。的gethostname()来确定当前的机器是什么类型的服务器:它返回发展制作测试

The _servers.py file contains a function get_server_type() that uses socket.gethostname() to determine what type of server the current machine is: it returns development, production or testing.

那么其他文件看起来有点像( production.py

Then the other files look a bit like (production.py):

DEBUG=False
TEMPLATE_DEBUG=False
from _base import *

在每一个文件,我把仅适用于该服务器类型的设置。

In each of these files, I put in the settings that only apply to this server type.

这篇关于管理多个settings.py文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆