1

我为 Django 创建了一个可重用的应用程序,它要求您在 settings.py 文件中添加设置。IE

version = '1'
url = 'api.domain.com'

但是,这些设置很少更改,我更希望它们成为我的包中的默认设置,但允许开发人员在他们自己的 settings.py 中覆盖它们。

我的包就像一个应用程序,所以它没有 settings.py 那么我如何在我的包中添加这些设置作为默认值,同时仍然允许它们在项目的开发人员 settings.py 中被覆盖?

我希望这是有道理的。

4

1 回答 1

1

A common thing that django folks do is to include a local_settings.py in your local copy for stuff that only want on your local copy. Then, at the end of your settings.py file, put:

try:
    from local_settings import *
except ImportError:
    pass

Be sure to add local_settings.py to your .gitignore (or equivalent for your VCS) so people aren't stepping on eachothers' feet by accidentally commiting local stuff.

于 2013-09-18T18:21:21.533 回答