如何模块化django settings.py? [英] how to modularize django settings.py?

查看:189
本文介绍了如何模块化django settings.py?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您安装新的django应用程序时,您必须添加/修改您的settings.py模块。

When you install a new django application, you have to add/modify your settings.py module.

对于一个项目,我试图使该模块python子包,并为每个应用程序创建一个模块:

For a project I'm trying to make that module a python subpackage and create a module for each application:

settings\
    __init__.py
    base.py
    admin.py
    feincms.py
    ...

我遇到的问题是如何将settings.py属性(INSTALLED_APPS例如是一个值的元组)合并到不同子模块中的值?

The problem I'm confronted with is how to merge settings.py attributes (INSTALLED_APPS for example is a tuple of values) that are getting values in the different submodules?

谢谢

好的,我问了一个错误的问题(得到正确的答案)。我的问题应该是,如何从所有子模块获取属性并合并? Django将导入设置并预期所有内容都将在那里。

Ok, I asked the wrong question (got the right answer for it though). My question should have been, how to get attributes from all submodules and merge them? Django will import settings and expects everything to be there.

推荐答案

您可能对这个解决方案;使用execfile()按顺序加载一系列设置文件,其中每个文件可以完全访问先前加载的文件的设置,更新,修改等。

You might be interested in this solution; uses execfile() to load a series of settings files in order, where each file has full access to settings from previously-loaded files, to update, modify, etc.

这篇关于如何模块化django settings.py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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